예제 #1
0
        private async Task <UserExerciseSubmission> TryGetExerciseSubmission(string agentName, List <string> sandboxes)
        {
            UserExerciseSubmission submission = null;

            while (submission == null)
            {
                var work = await workQueueRepo.Take(queueId, sandboxes);

                if (work == null)
                {
                    return(null);
                }

                var workItemId = int.Parse(work.ItemId);
                submission = await db.UserExerciseSubmissions
                             .Include(s => s.AutomaticChecking)
                             .Include(s => s.SolutionCode)
                             .FirstOrDefaultAsync(s => s.Id == workItemId &&
                                                  (s.AutomaticChecking.Status == AutomaticExerciseCheckingStatus.Waiting || s.AutomaticChecking.Status == AutomaticExerciseCheckingStatus.Running));

                var minutes      = TimeSpan.FromMinutes(15);
                var notSoLongAgo = DateTime.Now - TimeSpan.FromMinutes(15);
                if (submission == null)
                {
                    await workQueueRepo.Remove(work.Id);
                }
                else if (submission.Timestamp < notSoLongAgo)
                {
                    await workQueueRepo.Remove(work.Id);

                    submission.AutomaticChecking.Status = submission.AutomaticChecking.Status == AutomaticExerciseCheckingStatus.Waiting
                                                ? AutomaticExerciseCheckingStatus.RequestTimeLimit
                                                : AutomaticExerciseCheckingStatus.Error;
                    await db.SaveChangesAsync();

                    if (submission.AutomaticChecking.Status == AutomaticExerciseCheckingStatus.Error)
                    {
                        log.Error($"Не получил ответ от чеккера по проверке {submission.Id} за {minutes} минут");
                    }
                    if (!handledSubmissions.TryAdd(submission.Id, DateTime.Now))
                    {
                        log.Warn($"Не удалось запомнить, что {submission.Id} не удалось проверить, и этот результат сохранен в базу");
                    }
                    submission = null;
                }
            }

            submission.AutomaticChecking.Status            = AutomaticExerciseCheckingStatus.Running;
            submission.AutomaticChecking.CheckingAgentName = agentName;
            await db.SaveChangesAsync();

            unhandledSubmissions.TryRemove(submission.Id, out _);
            return(submission);
        }
예제 #2
0
        private async Task <Submission> ExtractSnippetsFromSubmissionFromQueue()
        {
            var queueItem = await workQueueRepo.Take(QueueIds.NewSubmissionsQueue).ConfigureAwait(false);

            if (queueItem == null)
            {
                return(null);
            }
            var submissionId = int.Parse(queueItem.ItemId);
            var submission   = (await submissionsRepo.GetSubmissionsByIdsAsync(new List <int> {
                submissionId
            }).ConfigureAwait(false)).First();

            await ExtractSnippetsFromSubmissionAsync(submission).ConfigureAwait(false);

            await workQueueRepo.Remove(queueItem.Id);

            return(submission);
        }