public async Task <int> QueueJudgeAsync(Judge judge) { judge.ResultType = (int)ResultCode.Pending; judge.JudgeCount++; var isRejudge = judge.Id != 0; if (isRejudge) { judge.Result = string.Empty; dbContext.Judge.Update(judge); } else { judge.JudgeTime = DateTime.Now; await dbContext.Judge.AddAsync(judge); if (judge.ContestId != null) { var problemConfig = await dbContext.ContestProblemConfig .Where(i => i.ContestId == judge.ContestId && i.ProblemId == judge.ProblemId).FirstOrDefaultAsync(); problemConfig.SubmissionCount++; } else { var problem = await dbContext.Problem.Where(i => i.Id == judge.ProblemId).FirstOrDefaultAsync(); problem.SubmissionCount++; } } await dbContext.SaveChangesAsync(); var(judgeOptionsBuilder, buildOptionsBuilder) = await JudgeHelper.GetOptionBuilders(problemService, judge, (await languageService.GetLanguageConfigAsync()).ToList()); var(judgeOptions, buildOptions) = (judgeOptionsBuilder.Build(), buildOptionsBuilder.Build()); var(channel, options) = messageQueueService.GetInstance("JudgeQueue"); var props = channel.CreateBasicProperties(); props.ContentType = "application/json"; props.DeliveryMode = 2; channel.BasicPublish( options.Exchange, options.RoutingKey, false, props, new JudgeInfo { JudgeId = judge.Id, Priority = isRejudge ? JudgePriority.Low : JudgePriority.Normal, JudgeOptions = judgeOptions, BuildOptions = buildOptions }.SerializeJson(false)); return(judge.Id); }