mirror of
https://github.com/C9Glax/tranga.git
synced 2025-05-22 06:03:01 +02:00
JobContext per Job
This commit is contained in:
parent
96d5b09391
commit
3fe3fc09b0
@ -67,14 +67,13 @@ public abstract class Job
|
|||||||
this.Log = LogManager.GetLogger(this.GetType());
|
this.Log = LogManager.GetLogger(this.GetType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Job> Run(IServiceProvider serviceProvider)
|
public IEnumerable<Job> Run(PgsqlContext context)
|
||||||
{
|
{
|
||||||
Log.Info($"Running job {JobId}");
|
Log.Info($"Running job {JobId}");
|
||||||
DateTime jobStart = DateTime.UtcNow;
|
DateTime jobStart = DateTime.UtcNow;
|
||||||
|
context.Attach(this);
|
||||||
Job[]? ret = null;
|
Job[]? ret = null;
|
||||||
|
|
||||||
using IServiceScope scope = serviceProvider.CreateScope();
|
|
||||||
PgsqlContext context = scope.ServiceProvider.GetRequiredService<PgsqlContext>();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.state = JobState.Running;
|
this.state = JobState.Running;
|
||||||
|
@ -172,7 +172,9 @@ public static class Tranga
|
|||||||
{
|
{
|
||||||
Thread t = new(() =>
|
Thread t = new(() =>
|
||||||
{
|
{
|
||||||
job.Run(serviceProvider);
|
using IServiceScope jobScope = serviceProvider.CreateScope();
|
||||||
|
PgsqlContext jobContext = jobScope.ServiceProvider.GetRequiredService<PgsqlContext>();
|
||||||
|
job.Run(jobContext);
|
||||||
});
|
});
|
||||||
RunningJobs.Add(t, job);
|
RunningJobs.Add(t, job);
|
||||||
t.Start();
|
t.Start();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user