Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            var data   = new OjsData();
            var random = new Random();

            while (true)
            {
                var submissions = data.Submissions.AllWithDeleted().Where(x => x.TestRuns.Count == 0);

                if (submissions.Count() != 0)
                {
                    Console.WriteLine("Found submissions.");
                }

                foreach (var submission in submissions)
                {
                    var problem = submission.Problem;
                    if (problem.Tests.Count == 0)
                    {
                        Console.WriteLine("Generating tests for problem.");
                        for (int i = 0; i < random.Next(8, 25); i++)
                        {
                            problem.Tests.Add(new Test
                            {
                                IsTrialTest = random.Next() % 2 == 0 ? true : false,
                                OrderBy     = random.Next()
                            });
                        }
                    }

                    foreach (var test in problem.Tests)
                    {
                        test.TestRuns.Add(new TestRun
                        {
                            MemoryUsed       = random.Next(),
                            ResultType       = (TestRunResultType)random.Next(0, 5),
                            TimeUsed         = random.Next(),
                            CheckerComment   = "Checker comment: " + Comments[random.Next(0, 3)],
                            ExecutionComment = "Executioner comment: " + Comments[random.Next(0, 3)],
                            SubmissionId     = submission.Id
                        });
                    }
                }

                data.SaveChanges();

                Console.WriteLine("Sleeping for 5s");
                System.Threading.Thread.Sleep(5000);
            }
        }
Ejemplo n.º 2
0
        public void Start()
        {
            this.logger.Info("SubmissionJob starting...");
            while (!this.stopping)
            {
                IOjsData   data = new OjsData();
                Submission submission;
                try
                {
                    submission = data.Submissions.GetSubmissionForProcessing();
                }
                catch (Exception exception)
                {
                    this.logger.FatalFormat("Unable to get submission for processing. Exception: {0}", exception);
                    throw;
                }

                if (submission == null)
                {
                    // No submission available. Wait 1 second and try again.
                    Thread.Sleep(1000);
                    continue;
                }

                if (!this.processingSubmissionIds.Add(submission.Id))
                {
                    // Other thread is processing the same submission. Wait the other thread to set Processing to true and then try again.
                    Thread.Sleep(100);
                    continue;
                }

                try
                {
                    submission.Processing = true;
                    data.SaveChanges();
                }
                catch (Exception exception)
                {
                    this.logger.Error("Unable to set dbSubmission.Processing to true! Exception: {0}", exception);
                    this.processingSubmissionIds.Remove(submission.Id);
                    throw;
                }

                submission.ProcessingComment = null;
                try
                {
                    data.TestRuns.DeleteBySubmissionId(submission.Id);
                    this.ProcessSubmission(submission);
                    data.SaveChanges();
                }
                catch (Exception exception)
                {
                    this.logger.ErrorFormat("ProcessSubmission on submission №{0} has thrown an exception: {1}", submission.Id, exception);
                    submission.ProcessingComment = string.Format("Exception in ProcessSubmission: {0}", exception.Message);
                }

                try
                {
                    this.CalculatePointsForSubmission(submission);
                }
                catch (Exception exception)
                {
                    this.logger.ErrorFormat("CalculatePointsForSubmission on submission №{0} has thrown an exception: {1}", submission.Id, exception);
                    submission.ProcessingComment = string.Format("Exception in CalculatePointsForSubmission: {0}", exception.Message);
                }

                submission.Processed  = true;
                submission.Processing = false;

                try
                {
                    data.SaveChanges();
                }
                catch (Exception exception)
                {
                    this.logger.ErrorFormat("Unable to save changes to the submission №{0}! Exception: {1}", submission.Id, exception);
                }

                // Next line removes the submission from the list. Fixes problem with retesting submissions.
                this.processingSubmissionIds.Remove(submission.Id);
            }

            this.logger.Info("SubmissionJob stopped.");
        }
Ejemplo n.º 3
0
        public void Start()
        {
            this.logger.Info("SubmissionJob starting...");
            while (!this.stopping)
            {
                var data = new OjsData();
                Submission submission;
                try
                {
                    submission = data.Submissions.GetSubmissionForProcessing();
                }
                catch (Exception exception)
                {
                    this.logger.FatalFormat("Unable to get submission for processing. Exception: {0}", exception);
                    throw;
                }

                if (submission == null)
                {
                    // No submission available. Wait 1 second and try again.
                    Thread.Sleep(1000);
                    continue;
                }

                if (!this.processingSubmissionIds.Add(submission.Id))
                {
                    // Other thread is processing the same submission. Wait the other thread to set Processing to true and then try again.
                    Thread.Sleep(100);
                    continue;
                }

                try
                {
                    submission.Processing = true;
                    data.SaveChanges();
                }
                catch (Exception exception)
                {
                    this.logger.Error("Unable to set dbSubmission.Processing to true! Exception: {0}", exception);
                    this.processingSubmissionIds.Remove(submission.Id);
                    throw;
                }

                submission.ProcessingComment = null;
                try
                {
                    data.TestRuns.DeleteBySubmissionId(submission.Id);
                    this.ProcessSubmission(submission);
                    data.SaveChanges();
                }
                catch (Exception exception)
                {
                    this.logger.ErrorFormat("ProcessSubmission on submission №{0} has thrown an exception: {1}", submission.Id, exception);
                    submission.ProcessingComment = string.Format("Exception in ProcessSubmission: {0}", exception.Message);
                }

                try
                {
                    this.CalculatePointsForSubmission(submission);
                }
                catch (Exception exception)
                {
                    this.logger.ErrorFormat("CalculatePointsForSubmission on submission №{0} has thrown an exception: {1}", submission.Id, exception);
                    submission.ProcessingComment = string.Format("Exception in CalculatePointsForSubmission: {0}", exception.Message);
                }

                submission.Processed = true;
                submission.Processing = false;

                try
                {
                    data.SaveChanges();
                }
                catch (Exception exception)
                {
                    this.logger.ErrorFormat("Unable to save changes to the submission №{0}! Exception: {1}", submission.Id, exception);
                }

                // Next line removes the submission from the list. Fixes problem with retesting submissions.
                this.processingSubmissionIds.Remove(submission.Id);
            }

            this.logger.Info("SubmissionJob stopped.");
        }
Ejemplo n.º 4
0
        public void Start()
        {
            this.logger.Info("SubmissionJob starting...");
            var container = Bootstrap.Container;

            while (!this.stopping)
            {
                using (ThreadScopedLifestyle.BeginScope(container))
                {
                    var data = new OjsData();
                    var submissionsForProccessingData = container.GetInstance <ISubmissionsForProcessingDataService>();
                    var participantScoresData         = container.GetInstance <IParticipantScoresDataService>();

                    Submission submission = null;
                    SubmissionForProcessing submissionForProcessing = null;
                    bool retrievedSubmissionSuccessfully;
                    try
                    {
                        lock (this.submissionsForProcessing)
                        {
                            if (this.submissionsForProcessing.IsEmpty)
                            {
                                var submissions = submissionsForProccessingData
                                                  .GetUnprocessedSubmissions()
                                                  .OrderBy(x => x.Id)
                                                  .Select(x => x.SubmissionId)
                                                  .ToList();

                                submissions.ForEach(this.submissionsForProcessing.Enqueue);
                            }

                            retrievedSubmissionSuccessfully = this.submissionsForProcessing
                                                              .TryDequeue(out var submissionId);

                            if (retrievedSubmissionSuccessfully)
                            {
                                this.logger
                                .InfoFormat($"Submission №{submissionId} retrieved from data store successfully");

                                submission = data.Submissions.GetById(submissionId);

                                submissionForProcessing = submissionsForProccessingData
                                                          .GetBySubmissionId(submissionId);

                                if (submission != null && submissionForProcessing != null && !submission.Processing)
                                {
                                    submissionsForProccessingData.SetToProcessing(submissionForProcessing.Id);
                                }
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        this.logger.FatalFormat("Unable to get submission for processing. Exception: {0}", exception);
                        throw;
                    }

                    if (retrievedSubmissionSuccessfully && submission != null && submissionForProcessing != null)
                    {
                        this.BeginProcessingSubmission(
                            submission,
                            submissionForProcessing,
                            data,
                            submissionsForProccessingData,
                            participantScoresData);
                    }
                    else
                    {
                        Thread.Sleep(1000);
                    }
                }
            }

            this.logger.Info("SubmissionJob stopped.");
        }