diff --git a/API/Schema/Jobs/Job.cs b/API/Schema/Jobs/Job.cs index e7c4ac6..7b70db2 100644 --- a/API/Schema/Jobs/Job.cs +++ b/API/Schema/Jobs/Job.cs @@ -67,14 +67,13 @@ public abstract class Job this.Log = LogManager.GetLogger(this.GetType()); } - public IEnumerable Run(IServiceProvider serviceProvider) + public IEnumerable Run(PgsqlContext context) { Log.Info($"Running job {JobId}"); DateTime jobStart = DateTime.UtcNow; + context.Attach(this); Job[]? ret = null; - using IServiceScope scope = serviceProvider.CreateScope(); - PgsqlContext context = scope.ServiceProvider.GetRequiredService(); try { this.state = JobState.Running; diff --git a/API/Tranga.cs b/API/Tranga.cs index fa37bd4..a5f7e8d 100644 --- a/API/Tranga.cs +++ b/API/Tranga.cs @@ -172,7 +172,9 @@ public static class Tranga { Thread t = new(() => { - job.Run(serviceProvider); + using IServiceScope jobScope = serviceProvider.CreateScope(); + PgsqlContext jobContext = jobScope.ServiceProvider.GetRequiredService(); + job.Run(jobContext); }); RunningJobs.Add(t, job); t.Start();