mirror of
https://github.com/C9Glax/tranga.git
synced 2025-05-22 06:03:01 +02:00
Let Job update itself in its own context
This commit is contained in:
parent
cb1c68f295
commit
8ecbdb91b2
@ -78,7 +78,8 @@ public abstract class Job
|
|||||||
this.state = JobState.Running;
|
this.state = JobState.Running;
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
ret = RunInternal(context).ToArray();
|
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);
|
context.Jobs.AddRange(ret);
|
||||||
Log.Info($"Job {JobId} completed. Generated {ret.Length} new jobs.");
|
Log.Info($"Job {JobId} completed. Generated {ret.Length} new jobs.");
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
@ -88,6 +89,8 @@ public abstract class Job
|
|||||||
if (e is not DbUpdateException)
|
if (e is not DbUpdateException)
|
||||||
{
|
{
|
||||||
this.state = JobState.Failed;
|
this.state = JobState.Failed;
|
||||||
|
this.Enabled = false;
|
||||||
|
this.LastExecution = DateTime.UtcNow;
|
||||||
Log.Error($"Failed to run job {JobId}", e);
|
Log.Error($"Failed to run job {JobId}", e);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user