Add missing job state transition (#2202)

* Add missing job state transition

* address PR comments
This commit is contained in:
Cheick Keita
2022-07-28 16:08:15 -07:00
committed by GitHub
parent b2fc9f4285
commit eaf74d936a

View File

@ -7,6 +7,7 @@ public interface IJobOperations : IStatefulOrm<Job, JobState> {
Async.Task OnStart(Job job);
IAsyncEnumerable<Job> SearchExpired();
Async.Task<Job> Stopping(Job job);
Async.Task<Job> Init(Job job);
IAsyncEnumerable<Job> SearchState(IEnumerable<JobState> states);
Async.Task StopNeverStartedJobs();
Async.Task StopIfAllDone(Job job);
@ -73,6 +74,17 @@ public class JobOperations : StatefulOrm<Job, JobState, JobOperations>, IJobOper
}
}
public async Async.Task<Job> Init(Job job) {
_logTracer.Info($"init job: {job.JobId}");
var enabled = job with { State = JobState.Enabled };
var result = await Replace(enabled);
if (result.IsOk) {
return enabled;
} else {
throw new Exception($"Failed to save job {job.JobId} : {result.ErrorV}");
}
}
public async Async.Task<Job> Stopping(Job job) {
job = job with { State = JobState.Stopping };
var tasks = await _context.TaskOperations.QueryAsync(filter: $"job_id eq '{job.JobId}'").ToListAsync();