示例#1
0
        public async Task RunAutomaticChecking(int submissionId, string sandbox, TimeSpan timeout, bool waitUntilChecked, int priority)
        {
            log.Info($"Запускаю автоматическую проверку решения. ID посылки: {submissionId}");
            UnhandledSubmissionsWaiter.UnhandledSubmissions.TryAdd(submissionId, DateTime.Now);
            await workQueueRepo.Add(queueId, submissionId.ToString(), sandbox ?? "csharp", priority);

            if (!waitUntilChecked)
            {
                log.Info($"Не буду ожидать результатов проверки посылки {submissionId}");
                return;
            }

            var sw = Stopwatch.StartNew();

            while (sw.Elapsed < timeout)
            {
                await UnhandledSubmissionsWaiter.WaitUntilSubmissionHandled(TimeSpan.FromSeconds(5), submissionId);

                var submissionAutomaticCheckingStatus = await GetSubmissionAutomaticCheckingStatus(submissionId);

                if (submissionAutomaticCheckingStatus == null)
                {
                    break;
                }

                if (submissionAutomaticCheckingStatus == AutomaticExerciseCheckingStatus.Done)
                {
                    log.Info($"Посылка {submissionId} проверена");
                    return;
                }
                if (submissionAutomaticCheckingStatus == AutomaticExerciseCheckingStatus.Error)
                {
                    log.Warn($"Во время проверки посылки {submissionId} произошла ошибка");
                    return;
                }
            }

            /* If something is wrong */
            UnhandledSubmissionsWaiter.UnhandledSubmissions.TryRemove(submissionId, out _);
            throw new SubmissionCheckingTimeout();
        }
示例#2
0
        public async Task <ActionResult <AddSubmissionResponse> > AddSubmission([FromQuery] string token, AddSubmissionParameters parameters)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (parameters.Code.Length > configuration.AntiPlagiarism.MaxCodeLength)
            {
                return(BadRequest(new ErrorResponse($"Code is too long. Maximum length is {configuration.AntiPlagiarism.MaxCodeLength} bytes")));
            }

            var tokensCount = GetTokensCount(parameters.Code, parameters.Language);
            var submission  = await submissionsRepo.AddSubmissionAsync(
                client.Id,
                parameters.TaskId,
                parameters.AuthorId,
                parameters.Language,
                parameters.Code,
                tokensCount,
                parameters.AdditionalInfo,
                parameters.ClientSubmissionId
                ).ConfigureAwait(false);

            log.Info(
                "Добавлено новое решение {submissionId} по задаче {taskId}, автор {authorId}, язык {language}, доп. информация {additionalInfo}",
                submission.Id,
                parameters.TaskId,
                parameters.AuthorId,
                parameters.Language,
                parameters.AdditionalInfo
                );

            await workQueueRepo.Add(QueueIds.NewSubmissionsQueue, submission.Id.ToString()).ConfigureAwait(false);

            return(new AddSubmissionResponse
            {
                SubmissionId = submission.Id,
            });
        }