Skip to content

Commit

Permalink
Add resources to a migration queue.
Browse files Browse the repository at this point in the history
  • Loading branch information
blattersturm committed May 25, 2019
1 parent e80e939 commit 5b03d61
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions server/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class Main : BaseScript
{
private bool m_ticked;

private readonly Queue<string> m_migrationQueue = new Queue<string>();

public Main()
{
Debug.WriteLine(typeof(MySql.Data.MySqlClient.MySqlConnection).Name);
Expand All @@ -40,6 +42,23 @@ public Main()

[EventHandler("onServerResourceStart")]
public async void OnServerResourceStart(string resourceName)
{
m_migrationQueue.Enqueue(resourceName);
}

[Tick]
public async Task RunTick()
{
m_ticked = true;

while (m_migrationQueue.Count > 0)
{
await Delay(0);
await MigrateResource(m_migrationQueue.Dequeue());
}
}

private async Task MigrateResource(string resourceName)
{
var cs = GetConvar("mysql_connection_string", "");
var numMetaData = GetNumResourceMetadata(resourceName, "migration_file");
Expand Down Expand Up @@ -110,12 +129,6 @@ public async void OnServerResourceStart(string resourceName)
}
}

[Tick]
public void RunTick()
{
m_ticked = true;
}

private async Task<Assembly> LoadMigrationAssembly(string resourceName, string fileName)
{
var fileData = LoadResourceFile(resourceName, fileName);
Expand Down Expand Up @@ -162,6 +175,7 @@ private async Task<Assembly> LoadMigrationAssembly(string resourceName, string f
MetadataReference.CreateFromStream(migratorStream),
MetadataReference.CreateFromStream(migratorStreamTwo)
)
.AddSyntaxTrees(syntaxTree);
using (var peStream = new MemoryStream())
Expand Down

0 comments on commit 5b03d61

Please sign in to comment.