[postgres-Server-V2] feat(Jobs): Instead of passing context to each job, pass service provider and let the job create its own context

This commit is contained in:
Alessandro Benetton
2025-02-01 23:08:13 +01:00
parent a69e12179b
commit 725813c2f3
3 changed files with 22 additions and 14 deletions

View File

@ -43,8 +43,11 @@ public abstract class Job
RecurrenceMs = recurrenceMs;
}
public IEnumerable<Job> Run(PgsqlContext context)
public IEnumerable<Job> Run(IServiceProvider serviceProvider)
{
using IServiceScope scope = serviceProvider.CreateScope();
PgsqlContext context = scope.ServiceProvider.GetRequiredService<PgsqlContext>();
this.state = JobState.Running;
IEnumerable<Job> newJobs = RunInternal(context);
this.state = JobState.Completed;