From 780c7c91cba50005f72ba74efe8d9cec0357322a Mon Sep 17 00:00:00 2001 From: Tobias Werth Date: Fri, 22 Nov 2024 17:30:30 +0100 Subject: [PATCH] Indicate to the judgehost to retry if we are cleaning up old queue tasks. Related: https://github.com/DOMjudge/domjudge/commit/80c1a43bfb85013ae5fa02b4bf60c4b3527d08f0 --- judge/judgedaemon.main.php | 12 ++++++++++++ webapp/src/Controller/API/JudgehostController.php | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/judge/judgedaemon.main.php b/judge/judgedaemon.main.php index 6d69bf13ee..f903b24222 100644 --- a/judge/judgedaemon.main.php +++ b/judge/judgedaemon.main.php @@ -60,6 +60,7 @@ function read_credentials(): void "waiting" => false, "errorred" => false, "last_attempt" => -1, + "retrying" => false, ]; } if (count($endpoints) <= 0) { @@ -785,8 +786,19 @@ function fetch_executable_internal( // We have gotten a work packet. $endpoints[$endpointID]["waiting"] = false; + // All tasks are guaranteed to be of the same type. $type = $row[0]['type']; + + if ($type == 'try_again') { + if (!$endpoints[$endpointID]['retrying']) { + logmsg(LOG_INFO, "API indicated to retry fetching work (this might take a while to clean up)."); + } + $endpoints[$endpointID]['retrying'] = true; + continue; + } + $endpoints[$endpointID]['retrying'] = false; + logmsg(LOG_INFO, "⇝ Received " . sizeof($row) . " '" . $type . "' judge tasks (endpoint $endpointID)"); diff --git a/webapp/src/Controller/API/JudgehostController.php b/webapp/src/Controller/API/JudgehostController.php index fd0c0fa6a2..6de3381fd9 100644 --- a/webapp/src/Controller/API/JudgehostController.php +++ b/webapp/src/Controller/API/JudgehostController.php @@ -1611,8 +1611,16 @@ public function getJudgeTasksAction(Request $request): array ->setMaxResults(1) ->getQuery() ->getOneOrNullResult(AbstractQuery::HYDRATE_SINGLE_SCALAR); + if ($jobid === null) { + return; + } $judgetasks = $this->getJudgetasks($jobid, $max_batchsize, $judgehost); - if ($judgetasks !== null) { + if (empty($judgetasks)) { + // Somehow we got ourselves in a situation that there was a queue task without remaining judge tasks. + // This should not happen, but if it does, we need to clean up. Each of the fetch-work calls will clean + // up one queue task. We need to signal to the judgehost that there might be more work to do. + $judgetasks = [['type' => 'try_again']]; + } else { // Mark it as being worked on. $this->em->createQueryBuilder() ->update(QueueTask::class, 'qt')