Skip to content

Commit

Permalink
Temporary hack to mirror problems list to all judges
Browse files Browse the repository at this point in the history
  • Loading branch information
hieplpvip committed Sep 19, 2024
1 parent 772836a commit 639d465
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
21 changes: 9 additions & 12 deletions judge/bridge/judge_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']

Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions judge/bridge/judge_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 639d465

Please sign in to comment.