Let Job update itself in its own context

This commit is contained in:
Glax 2025-05-18 16:06:52 +02:00
parent cb1c68f295
commit 8ecbdb91b2

View File

@ -78,7 +78,8 @@ public abstract class Job
this.state = JobState.Running;
context.SaveChanges();
ret = RunInternal(context).ToArray();
this.state = JobState.Completed;
this.state = this.RecurrenceMs > 0 ? JobState.CompletedWaiting : JobState.Completed;
this.LastExecution = DateTime.UtcNow;
context.Jobs.AddRange(ret);
Log.Info($"Job {JobId} completed. Generated {ret.Length} new jobs.");
context.SaveChanges();
@ -88,6 +89,8 @@ public abstract class Job
if (e is not DbUpdateException)
{
this.state = JobState.Failed;
this.Enabled = false;
this.LastExecution = DateTime.UtcNow;
Log.Error($"Failed to run job {JobId}", e);
context.SaveChanges();
}