From 639d465ecc708a7834ac640c7c34df44b7656d5c Mon Sep 17 00:00:00 2001 From: Le Bao Hiep Date: Thu, 25 Jan 2024 02:17:43 +0700 Subject: [PATCH] Temporary hack to mirror problems list to all judges --- judge/bridge/judge_handler.py | 21 +++++++++------------ judge/bridge/judge_list.py | 7 +++++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/judge/bridge/judge_handler.py b/judge/bridge/judge_handler.py index 3b3845952..ee81c8959 100644 --- a/judge/bridge/judge_handler.py +++ b/judge/bridge/judge_handler.py @@ -57,7 +57,6 @@ def __init__(self, request, client_address, server, judges): } self._working = False self._no_response_job = None - self._problems = [] self.executors = {} self.problems = {} self.latency = None @@ -166,8 +165,7 @@ def on_handshake(self, packet): return self.timeout = 60 - self._problems = packet['problems'] - self.problems = dict(self._problems) + self.problems = dict(packet['problems']) self.executors = packet['executors'] self.name = packet['id'] @@ -325,19 +323,18 @@ def _submission_is_batch(self, id): if not Submission.objects.filter(id=id).update(batch=True): logger.warning('Unknown submission: %s', id) - def on_supported_problems(self, packet): + def update_problems(self, problems, problem_ids): logger.info('%s: Updating problem list', self.name) - self._problems = packet['problems'] - self.problems = dict(self._problems) - if not self.working: - self.judges.update_problems(self) - - self.judge.problems.set( - Problem.objects.filter(code__in=list(self.problems.keys())).values_list('id', flat=True), - ) + self.problems = problems + self.judge.problems.set(problem_ids) logger.info('%s: Updated %d problems', self.name, len(self.problems)) json_log.info(self._make_json_log(action='update-problems', count=len(self.problems))) + def on_supported_problems(self, packet): + problems = dict(packet['problems']) + problem_ids = list(Problem.objects.filter(code__in=list(self.problems.keys())).values_list('id', flat=True)) + self.judges.update_problems(problems, problem_ids) + def on_grading_begin(self, packet): logger.info('%s: Grading has begun on: %s', self.name, packet['submission-id']) self.batch_id = None diff --git a/judge/bridge/judge_list.py b/judge/bridge/judge_list.py index b7c542d0e..c4ea9417c 100644 --- a/judge/bridge/judge_list.py +++ b/judge/bridge/judge_list.py @@ -68,9 +68,12 @@ def disconnect(self, judge_id, force=False): if judge.name == judge_id: judge.disconnect(force=force) - def update_problems(self, judge): + def update_problems(self, problems, problem_ids): with self.lock: - self._handle_free_judge(judge) + for judge in self.judges: + judge.update_problems(problems, problem_ids) + if not judge.working: + self._handle_free_judge(judge) def update_disable_judge(self, judge_id, is_disabled): with self.lock: