mirror of
https://github.com/C9Glax/tranga.git
synced 2025-05-22 14:13:01 +02:00
Do not update context.Jobs on every cycle
This commit is contained in:
parent
065cac62af
commit
110dd36166
@ -96,6 +96,7 @@ public static class Tranga
|
|||||||
private static readonly Dictionary<Thread, Job> RunningJobs = new();
|
private static readonly Dictionary<Thread, Job> RunningJobs = new();
|
||||||
private static void JobStarter(object? serviceProviderObj)
|
private static void JobStarter(object? serviceProviderObj)
|
||||||
{
|
{
|
||||||
|
Log.Info("JobStarter Thread running.");
|
||||||
if (serviceProviderObj is null)
|
if (serviceProviderObj is null)
|
||||||
{
|
{
|
||||||
Log.Error("serviceProviderObj is null");
|
Log.Error("serviceProviderObj is null");
|
||||||
@ -103,23 +104,22 @@ public static class Tranga
|
|||||||
}
|
}
|
||||||
IServiceProvider serviceProvider = (IServiceProvider)serviceProviderObj;
|
IServiceProvider serviceProvider = (IServiceProvider)serviceProviderObj;
|
||||||
using IServiceScope scope = serviceProvider.CreateScope();
|
using IServiceScope scope = serviceProvider.CreateScope();
|
||||||
PgsqlContext? context = scope.ServiceProvider.GetService<PgsqlContext>();
|
PgsqlContext context = scope.ServiceProvider.GetRequiredService<PgsqlContext>();
|
||||||
if (context is null)
|
|
||||||
{
|
DateTime lastContextUpdate = DateTime.UnixEpoch;
|
||||||
Log.Error("PgsqlContext is null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.Info(TRANGA);
|
|
||||||
Log.Info("Loading Jobs");
|
|
||||||
context.Jobs.Load();
|
|
||||||
Log.Info("JobStarter Thread running.");
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
if (lastContextUpdate.AddMilliseconds(TrangaSettings.startNewJobTimeoutMs * 10) < DateTime.UtcNow)
|
||||||
|
{
|
||||||
|
Log.Info("Loading Jobs...");
|
||||||
|
context.Jobs.Load();
|
||||||
|
lastContextUpdate = DateTime.UtcNow;
|
||||||
|
Log.Info("Jobs Loaded!");
|
||||||
|
}
|
||||||
foreach (EntityEntry entityEntry in context.ChangeTracker.Entries().ToArray())
|
foreach (EntityEntry entityEntry in context.ChangeTracker.Entries().ToArray())
|
||||||
entityEntry.Reload();
|
entityEntry.Reload();
|
||||||
//Update finished Jobs to new states
|
//Update finished Jobs to new states
|
||||||
context.Jobs.Load();
|
|
||||||
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)
|
||||||
if (completedJob.RecurrenceMs <= 0)
|
if (completedJob.RecurrenceMs <= 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user