From c33faf1607e32a5734a74eaefe81819fed311b85 Mon Sep 17 00:00:00 2001 From: Tobias Werth Date: Fri, 2 Apr 2021 21:49:21 +0200 Subject: [PATCH] Add option to specify priority for rejudgings. Fixes #639. --- webapp/src/Controller/API/JudgehostController.php | 3 ++- webapp/src/Controller/Jury/RejudgingController.php | 9 ++++++--- webapp/src/Entity/JudgeTask.php | 12 ++++++++++++ webapp/src/Form/Type/RejudgingType.php | 10 ++++++++++ webapp/src/Service/DOMJudgeService.php | 4 ++-- webapp/src/Service/RejudgingService.php | 4 +++- .../templates/jury/partials/rejudge_form.html.twig | 8 ++++++++ 7 files changed, 43 insertions(+), 7 deletions(-) diff --git a/webapp/src/Controller/API/JudgehostController.php b/webapp/src/Controller/API/JudgehostController.php index d8f5cd21e0..9caf1cc4f3 100644 --- a/webapp/src/Controller/API/JudgehostController.php +++ b/webapp/src/Controller/API/JudgehostController.php @@ -1094,7 +1094,8 @@ private function maybeUpdateActiveJudging(Judging $judging): void ->getQuery() ->setHint(Query::HINT_REFRESH, TRUE) ->getResult(); - $this->rejudgingService->createRejudging($rejudging->getReason(), $judgings, + // TOOD: Pick up priority from previous judgings? + $this->rejudgingService->createRejudging($rejudging->getReason(), JudgeTask::PRIORITY_DEFAULT, $judgings, false, $rejudging->getRepeat(), $rejudging->getRepeatedRejudging(), $skipped); } } diff --git a/webapp/src/Controller/Jury/RejudgingController.php b/webapp/src/Controller/Jury/RejudgingController.php index 080e7bd31d..98df58723f 100644 --- a/webapp/src/Controller/Jury/RejudgingController.php +++ b/webapp/src/Controller/Jury/RejudgingController.php @@ -5,6 +5,7 @@ use App\Controller\BaseController; use App\Entity\Contest; use App\Entity\Judgehost; +use App\Entity\JudgeTask; use App\Entity\Judging; use App\Entity\JudgingRun; use App\Entity\Language; @@ -471,6 +472,7 @@ public function addAction(Request $request, FormFactoryInterface $formFactory): $formData = $form->getData(); $data = [ 'reason' => $formData['reason'], + 'priority' => JudgeTask::parsePriority($formData['priority']), 'repeat' => $formData['repeat'], 'contests' => array_map(function (Contest $contest) { return $contest->getCid(); @@ -588,7 +590,7 @@ public function addAction(Request $request, FormFactoryInterface $formFactory): $skipped = []; $res = $this->rejudgingService->createRejudging( - $reason, $judgings, false, (int)$data['repeat'] ?? 1, null, $skipped, $progressReporter); + $reason, $data['priority'], $judgings, false, (int)$data['repeat'] ?? 1, null, $skipped, $progressReporter); $this->generateFlashMessagesForSkippedJudgings($skipped); if ($res === null) { @@ -620,6 +622,7 @@ public function createAction(Request $request): Response $includeAll = (bool)$request->request->get('include_all'); $autoApply = (bool)$request->request->get('auto_apply'); $repeat = (int)$request->request->get('repeat'); + $priority = $request->request->get('priority') ?: 'default'; if (empty($table) || empty($id)) { throw new BadRequestHttpException('No table or id passed for selection in rejudging'); @@ -672,7 +675,7 @@ public function createAction(Request $request): Response flush(); }; - return $this->streamResponse(function() use ($progressReporter, $repeat, $reason, $request, $autoApply, $includeAll, $id, $table, $tablemap) { + return $this->streamResponse(function() use ($priority, $progressReporter, $repeat, $reason, $request, $autoApply, $includeAll, $id, $table, $tablemap) { // Only rejudge submissions in active contests. $contests = $this->dj->getCurrentContests(); @@ -719,7 +722,7 @@ public function createAction(Request $request): Response } $skipped = []; - $res = $this->rejudgingService->createRejudging($reason, $judgings, $autoApply, $repeat, null, $skipped, $progressReporter); + $res = $this->rejudgingService->createRejudging($reason, JudgeTask::parsePriority($priority), $judgings, $autoApply, $repeat, null, $skipped, $progressReporter); $this->generateFlashMessagesForSkippedJudgings($skipped); if ($res === null) { diff --git a/webapp/src/Entity/JudgeTask.php b/webapp/src/Entity/JudgeTask.php index 1bbc68c4f3..0ff63278de 100644 --- a/webapp/src/Entity/JudgeTask.php +++ b/webapp/src/Entity/JudgeTask.php @@ -337,4 +337,16 @@ public function getStarttime() { return $this->starttime; } + + public static function parsePriority(string $priorityString): int { + switch ($priorityString) { + case 'low': + return JudgeTask::PRIORITY_LOW; + case 'high': + return JudgeTask::PRIORITY_HIGH; + default: + return JudgeTask::PRIORITY_DEFAULT; + + } + } } diff --git a/webapp/src/Form/Type/RejudgingType.php b/webapp/src/Form/Type/RejudgingType.php index 5b9be5760e..3b6408f376 100644 --- a/webapp/src/Form/Type/RejudgingType.php +++ b/webapp/src/Form/Type/RejudgingType.php @@ -44,6 +44,16 @@ public function __construct(EntityManagerInterface $em) public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('reason', TextType::class); + $builder->add('priority', ChoiceType::class, + [ + 'choices' => [ + 'low' => 'low', + 'default' => 'default', + 'high' => 'high', + ], + 'data' => 'default', + ] + ); $builder->add('repeat', IntegerType::class, [ 'label' => 'Number of times to repeat this rejudging', 'data' => 1, diff --git a/webapp/src/Service/DOMJudgeService.php b/webapp/src/Service/DOMJudgeService.php index 782f5bf4eb..fb6cd4fca8 100644 --- a/webapp/src/Service/DOMJudgeService.php +++ b/webapp/src/Service/DOMJudgeService.php @@ -1078,7 +1078,7 @@ public function unblockJudgeTasksForProblem(int $probId): void } } - public function maybeCreateJudgeTasks(Judging $judging): void + public function maybeCreateJudgeTasks(Judging $judging, int $priority = JudgeTask::PRIORITY_DEFAULT): void { $submission = $judging->getSubmission(); $problem = $submission->getContestProblem(); @@ -1107,7 +1107,7 @@ public function maybeCreateJudgeTasks(Judging $judging): void $judgetaskInsertParams = [ ':type' => JudgeTaskType::JUDGING_RUN, ':submitid' => $submission->getSubmitid(), - ':priority' => JudgeTask::PRIORITY_DEFAULT, + ':priority' => $priority, ':jobid' => $judging->getJudgingid(), ':compile_script_id' => $compileExecutable->getImmutableExecId(), ':compare_script_id' => $compareExecutable->getImmutableExecId(), diff --git a/webapp/src/Service/RejudgingService.php b/webapp/src/Service/RejudgingService.php index 3b872fbbb3..21527910b5 100644 --- a/webapp/src/Service/RejudgingService.php +++ b/webapp/src/Service/RejudgingService.php @@ -86,6 +86,7 @@ public function __construct( */ public function createRejudging( string $reason, + int $priority, array $judgings, bool $autoApply, int $repeat, @@ -129,6 +130,7 @@ public function createRejudging( } $this->em->transactional(function () use ( + $priority, $singleJudging, $judging, $rejudging @@ -164,7 +166,7 @@ public function createRejudging( $this->em->persist($newJudging); $this->em->flush(); - $this->dj->maybeCreateJudgeTasks($newJudging); + $this->dj->maybeCreateJudgeTasks($newJudging, $priority); }); if ($index > 1) { diff --git a/webapp/templates/jury/partials/rejudge_form.html.twig b/webapp/templates/jury/partials/rejudge_form.html.twig index e89d5847b2..b6b99a3cf5 100644 --- a/webapp/templates/jury/partials/rejudge_form.html.twig +++ b/webapp/templates/jury/partials/rejudge_form.html.twig @@ -86,6 +86,14 @@ +
+ + +
{% endif %}