Update Jobs on each cycle (since it is super fast now)

This commit is contained in:
Glax 2025-05-16 21:09:43 +02:00
parent d6e945741a
commit 8e0c964883

View File

@ -106,19 +106,15 @@ public static class Tranga
using IServiceScope scope = serviceProvider.CreateScope(); using IServiceScope scope = serviceProvider.CreateScope();
PgsqlContext context = scope.ServiceProvider.GetRequiredService<PgsqlContext>(); PgsqlContext context = scope.ServiceProvider.GetRequiredService<PgsqlContext>();
DateTime lastContextUpdate = DateTime.UnixEpoch;
while (true) while (true)
{
if (lastContextUpdate.AddMilliseconds(TrangaSettings.startNewJobTimeoutMs * 10) < DateTime.UtcNow)
{ {
Log.Info("Loading Jobs..."); Log.Info("Loading Jobs...");
DateTime loadStart = DateTime.UtcNow;
context.Jobs.Load(); context.Jobs.Load();
lastContextUpdate = DateTime.UtcNow; Log.Info("Updating Entries...");
Log.Info("Jobs Loaded!");
}
foreach (EntityEntry entityEntry in context.ChangeTracker.Entries().ToArray()) foreach (EntityEntry entityEntry in context.ChangeTracker.Entries().ToArray())
entityEntry.Reload(); entityEntry.Reload();
Log.Info($"Jobs Loaded! (took {DateTime.UtcNow.Subtract(loadStart).TotalMilliseconds}ms)");
//Update finished Jobs to new states //Update finished Jobs to new states
List<Job> completedJobs = context.Jobs.Local.Where(j => j.state == JobState.Completed).ToList(); List<Job> completedJobs = context.Jobs.Local.Where(j => j.state == JobState.Completed).ToList();
foreach (Job completedJob in completedJobs) foreach (Job completedJob in completedJobs)