From a0da0b5fa6d87a65500858ad6fe72e8ce847d486 Mon Sep 17 00:00:00 2001 From: virusdefender Date: Tue, 27 Mar 2018 13:14:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=20submission=5Fnumb?= =?UTF-8?q?er=20=E4=B8=8D=E5=8F=98=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- judge/dispatcher.py | 16 ++++++++-------- judge/tasks.py | 4 ++-- submission/views/admin.py | 5 ++--- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/judge/dispatcher.py b/judge/dispatcher.py index 2e433435..eaa010fa 100644 --- a/judge/dispatcher.py +++ b/judge/dispatcher.py @@ -85,10 +85,13 @@ class SPJCompiler(DispatcherBase): class JudgeDispatcher(DispatcherBase): - def __init__(self, submission_id, problem_id): + def __init__(self, submission_id, problem_id, is_rejudge=False): super().__init__() self.submission = Submission.objects.get(id=submission_id) self.contest_id = self.submission.contest_id + self.is_rejudge = is_rejudge + self.last_result = None + if self.contest_id: self.problem = Problem.objects.select_related("contest").get(id=problem_id, contest_id=self.contest_id) self.contest = self.problem.contest @@ -119,7 +122,7 @@ class JudgeDispatcher(DispatcherBase): def judge(self): server = self.choose_judge_server() if not server: - data = {"submission_id": self.submission.id, "problem_id": self.problem.id} + data = {"submission_id": self.submission.id, "problem_id": self.problem.id, "is_rejudge": self.is_rejudge} cache.lpush(CacheKey.waiting_queue, json.dumps(data)) return @@ -150,11 +153,8 @@ class JudgeDispatcher(DispatcherBase): "spj_compile_config": spj_config.get("compile"), "spj_src": self.problem.spj_code } - self.last_result = None - try: - self.last_result = Submission.objects.get(id=self.submission.id).result - except Submission.DoesNotExist: - pass + self.last_result = self.submission.result + Submission.objects.filter(id=self.submission.id).update(result=JudgeStatus.JUDGING) resp = self._request(urljoin(server.service_url, "/judge"), data=data) @@ -197,7 +197,7 @@ class JudgeDispatcher(DispatcherBase): with transaction.atomic(): # update problem status problem = Problem.objects.select_for_update().get(contest_id=self.contest_id, id=self.problem.id) - if not self.last_result: + if not self.is_rejudge: problem.submission_number += 1 if self.submission.result == JudgeStatus.ACCEPTED: if self.last_result != JudgeStatus.ACCEPTED: diff --git a/judge/tasks.py b/judge/tasks.py index eda9e0f4..a0fab546 100644 --- a/judge/tasks.py +++ b/judge/tasks.py @@ -4,5 +4,5 @@ from judge.dispatcher import JudgeDispatcher @shared_task -def judge_task(submission_id, problem_id): - JudgeDispatcher(submission_id, problem_id).judge() +def judge_task(submission_id, problem_id, is_rejudge=False): + JudgeDispatcher(submission_id, problem_id, is_rejudge=is_rejudge).judge() diff --git a/submission/views/admin.py b/submission/views/admin.py index 679360b6..0638b970 100644 --- a/submission/views/admin.py +++ b/submission/views/admin.py @@ -10,15 +10,14 @@ class SubmissionRejudgeAPI(APIView): def get(self, request): id = request.GET.get("id") if not id: - return self.error("Paramater error, id is required") + return self.error("Parameter error, id is required") try: submission = Submission.objects.select_related("problem").get(id=id, contest_id__isnull=True) except Submission.DoesNotExist: return self.error("Submission does not exists") - submission.result = JudgeStatus.PENDING submission.info = {} submission.statistic_info = {} submission.save() - judge_task.delay(submission.id, submission.problem.id) + judge_task.delay(submission.id, submission.problem.id, is_rejudge=True) return self.success()