public async Task StateChanged(JobState jobState) { //TODO: Validate jobState if (jobState == null) { var ci = Context.GetClient(); _logger.LogError($"{nameof(jobState)} is null from {ci}"); return; } var oldJobState = await _store.GetJobState(jobState.TraceId, jobState.Client, jobState.Sharding); if (oldJobState == null) { var ci = Context.GetClient(); _logger.LogError($"{ci} {jobState.TraceId}, {jobState.Client}, {jobState.Sharding} is not exists"); return; } else { jobState.Id = oldJobState.Id; await _store.UpdateJobState(jobState); } switch (jobState.State) { case State.Exit: if (await _store.IsJobExited(jobState.JobId)) { await _store.ChangeJobState(jobState.JobId, State.Exit); } break; case State.Running: await _store.ChangeJobState(jobState.JobId, State.Running); break; } }
public async Task <IActionResult> Exit(string jobId) { if (string.IsNullOrWhiteSpace(jobId)) { return(new JsonResult(new ApiResult(ApiResult.Error, "Id is empty/null"))); } var job = await _store.GetJob(jobId); if (job == null) { return(new JsonResult(new ApiResult(ApiResult.Error, $"Job {jobId} not exists"))); } ApiResult result; switch (job.Performer) { case Performer.SignalR: { await _hubContext.Clients.All.SendAsync("Kill", jobId); result = new ApiResult(ApiResult.SuccessCode, "success"); break; } default: { result = new ApiResult(ApiResult.Error, $"Performer {job.Performer} is not support to exit"); break; } } await _store.ChangeJobState(jobId, State.Exit); return(new JsonResult(result)); }