public ActionResult SendJobResult( [FromBody] JobResultMsg resultMsg, [FromServices] JudgerCoordinatorService coordinator) { var judger = AuthHelper.ExtractUsername(HttpContext.User); coordinator.OnJobResultMessage(judger !, resultMsg); return(NoContent()); }
public async void OnJobResultMessage(string clientId, JobResultMsg msg) { using var scope = scopeProvider.CreateScope(); var db = GetDb(scope); using var tx = await db.Database.BeginTransactionAsync(); var job = await db.Jobs.Where(job => job.Id == msg.JobId).SingleOrDefaultAsync(); if (!ShouldAddResult(job)) { logger.LogError("Judger {0} tried to add result to a stopped job {1}, error?", clientId, msg.JobId); return; } var buildResultFilename = await UploadJobBuildOutput(msg.JobId); if (job == null) { logger.LogError("Unable to find job {0} ({1}) in database! Please recheck", msg.JobId, msg.JobId.Num); return; } frontendService.OnJobStautsUpdate(msg.JobId, new Models.WebsocketApi.JobStatusUpdateMsg { JobId = msg.JobId, BuildOutputFile = buildResultFilename, Stage = JobStage.Finished, JobResult = msg.JobResult, TestResult = msg.Results }); job.BuildOutputFile = buildResultFilename; job.Results = msg.Results ?? new Dictionary <string, TestResult>(); job.Stage = JobStage.Finished; job.ResultKind = msg.JobResult; job.ResultMessage = msg.Message; job.FinishTime = DateTimeOffset.Now; await db.SaveChangesAsync(); await tx.CommitAsync(); }