Exemplo n.º 1
0
        public async Task <IActionResult> UpdateJudging(
            [FromRoute] string hostname,
            [FromRoute] int judgingId,
            [FromForm] UpdateJudgingModel model)
        {
            var host = await Judgehosts.FindAsync(hostname);

            // Unknown or inactive judgehost requested
            if (host is null)
            {
                return(Empty());
            }
            await Judgehosts.NotifyPollAsync(host);

            var(judging, pid, cid, uid, time) = await Judgings.FindAsync(judgingId);

            if (judging is null)
            {
                return(BadRequest());
            }
            judging.CompileError = model.output_compile ?? "";

            if (model.compile_success != 1)
            {
                judging.Status   = Verdict.CompileError;
                judging.StopTime = DateTimeOffset.Now;
                await FinishJudging(judging, cid, pid, uid, time);
            }
            else
            {
                await Judgings.UpdateAsync(judging);
            }

            return(Ok());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateJudging(
            [FromRoute] string hostname,
            [FromRoute] int judgingId,
            [FromForm] UpdateJudgingModel model)
        {
            int jid  = judgingId;
            var host = await DbContext.JudgeHosts
                       .Where(h => h.ServerName == hostname)
                       .FirstOrDefaultAsync();

            // Unknown or inactive judgehost requested
            if (host is null)
            {
                return(JsonEmpty());
            }
            host.PollTime = DateTimeOffset.Now;
            DbContext.JudgeHosts.Update(host);

            var judging = await DbContext.Judgings
                          .Where(g => g.JudgingId == jid)
                          .FirstOrDefaultAsync();

            if (judging is null)
            {
                return(BadRequest());
            }
            judging.CompileError = model.output_compile ?? "";

            if (model.compile_success != 1)
            {
                judging.Status   = Verdict.CompileError;
                judging.StopTime = DateTimeOffset.Now;

                var cid = await(
                    from j in DbContext.Judgings
                    where j.JudgingId == jid
                    join s in DbContext.Submissions on j.SubmissionId equals s.SubmissionId
                    select s.ContestId
                    ).FirstAsync();

                DbContext.AuditLogs.Add(new AuditLog
                {
                    Comment   = $"judged {judging.Status}",
                    EntityId  = judging.JudgingId,
                    ContestId = cid,
                    Resolved  = cid == 0,
                    Time      = DateTimeOffset.Now,
                    Type      = AuditLog.TargetType.Judging,
                    UserName  = hostname,
                });

                Telemetry.TrackDependency(
                    dependencyTypeName: "JudgeHost",
                    dependencyName: host.ServerName,
                    data: $"j{judging.JudgingId} judged " + Verdict.CompileError,
                    startTime: judging.StartTime ?? DateTimeOffset.Now,
                    duration: (judging.StopTime - judging.StartTime) ?? TimeSpan.Zero,
                    success: true);
            }

            judging.ServerId = host.ServerId;
            DbContext.Judgings.Update(judging);
            await DbContext.SaveChangesAsync();

            return(Ok());
        }