JobContext per Job

This commit is contained in:
Glax 2025-05-18 15:21:59 +02:00
parent 96d5b09391
commit 3fe3fc09b0
2 changed files with 5 additions and 4 deletions

View File

@ -67,14 +67,13 @@ public abstract class Job
this.Log = LogManager.GetLogger(this.GetType());
}
public IEnumerable<Job> Run(IServiceProvider serviceProvider)
public IEnumerable<Job> 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<PgsqlContext>();
try
{
this.state = JobState.Running;

View File

@ -172,7 +172,9 @@ public static class Tranga
{
Thread t = new(() =>
{
job.Run(serviceProvider);
using IServiceScope jobScope = serviceProvider.CreateScope();
PgsqlContext jobContext = jobScope.ServiceProvider.GetRequiredService<PgsqlContext>();
job.Run(jobContext);
});
RunningJobs.Add(t, job);
t.Start();