コード例 #1
0
ファイル: views.py プロジェクト: Timeship/OnlineJudge-QDU
    def post(self, request):
        serializer = SubmissionRejudgeSerializer(data=request.data)
        if serializer.is_valid():
            submission_id = serializer.data["submission_id"]
            try:
                submission = Submission.objects.get(id=submission_id)
            except Submission.DoesNotExist:
                return error_response(u"提交不存在")
            # 目前只考虑前台公开题目的重新判题
            try:
                problem = Problem.objects.get(id=submission.problem_id)
            except Problem.DoesNotExist:
                return error_response(u"题目不存在")
            try:
                judge.delay(submission_id, problem.time_limit, problem.memory_limit, problem.test_case_id)
            except Exception as e:
                logger.error(e)
                return error_response(u"提交判题任务失败")

            # 增加redis 中判题队列长度的计数器
            r = redis.Redis(host=redis_config["host"], port=redis_config["port"], db=redis_config["db"])
            r.incr("judge_queue_length")
            return success_response(u"任务提交成功")
        else:
            return serializer_invalid_response(serializer)
コード例 #2
0
ファイル: views.py プロジェクト: hujingguang/OnlineJudge
 def post(self, request):
     """
     创建比赛的提交
     ---
     request_serializer: CreateContestSubmissionSerializer
     """
     serializer = CreateContestSubmissionSerializer(data=request.data)
     if serializer.is_valid():
         data = serializer.data
         contest = Contest.objects.get(id=data["contest_id"])
         try:
             problem = ContestProblem.objects.get(contest=contest, id=data["problem_id"])
             # 更新题目提交计数器
             problem.total_submit_number += 1
             problem.save()
         except ContestProblem.DoesNotExist:
             return error_response(u"题目不存在")
         submission = Submission.objects.create(user_id=request.user.id, language=int(data["language"]),
                                                contest_id=contest.id, code=data["code"], problem_id=problem.id)
         try:
             judge.delay(submission.id, problem.time_limit, problem.memory_limit, problem.test_case_id)
         except Exception:
             return error_response(u"提交判题任务失败")
         # 增加redis 中判题队列长度的计数器
         r = redis.Redis(host=redis_config["host"], port=redis_config["port"], db=redis_config["db"])
         r.incr("judge_queue_length")
         return success_response({"submission_id": submission.id})
     else:
         return serializer_invalid_response(serializer)
コード例 #3
0
ファイル: views.py プロジェクト: eduStack/OnlineJudge
    def post(self, request):
        """
        提交代码
        ---
        request_serializer: CreateSubmissionSerializer
        """
        serializer = CreateSubmissionSerializer(data=request.data)
        if serializer.is_valid():
            data = serializer.data
            try:
                problem = Problem.objects.get(id=data["problem_id"])
            except Problem.DoesNotExist:
                return error_response(u"题目不存在")
            submission = Submission.objects.create(user_id=request.user.id, language=int(data["language"]),
                                                   code=data["code"], problem_id=problem.id)

            try:
                judge.delay(submission.id, problem.time_limit, problem.memory_limit, problem.test_case_id)
            except Exception as e:
                logger.error(e)
                return error_response(u"提交判题任务失败")
            r = redis.Redis(host=redis_config["host"], port=redis_config["port"], db=redis_config["db"])
            r.incr("judge_queue_length")

            return success_response({"submission_id": submission.id})
        else:
            return serializer_invalid_response(serializer)
コード例 #4
0
ファイル: views.py プロジェクト: Timeship/OnlineJudge-QDU
    def post(self, request):
        """
        提交代码
        ---
        request_serializer: CreateSubmissionSerializer
        """
        serializer = CreateSubmissionSerializer(data=request.data)
        if serializer.is_valid():
            data = serializer.data
            try:
                problem = Problem.objects.get(id=data["problem_id"])
                # 更新问题的总提交计数
                problem.total_submit_number += 1
                problem.save()
            except Problem.DoesNotExist:
                return error_response(u"题目不存在")
            submission = Submission.objects.create(user_id=request.user.id, language=int(data["language"]),
                                                   code=data["code"], problem_id=problem.id)

            try:
                judge.delay(submission.id, problem.time_limit, problem.memory_limit, problem.test_case_id)
            except Exception as e:
                logger.error(e)
                return error_response(u"提交判题任务失败")
            # 修改用户解题状态
            problems_status = request.user.problems_status
            if "problems" not in problems_status:
                problems_status["problems"] = {}
            problems_status["problems"][str(data["problem_id"])] = 2
            request.user.problems_status = problems_status
            request.user.save()
            # 增加redis 中判题队列长度的计数器
            r = redis.Redis(host=redis_config["host"], port=redis_config["port"], db=redis_config["db"])
            r.incr("judge_queue_length")

            return success_response({"submission_id": submission.id})
        else:
            return serializer_invalid_response(serializer)
コード例 #5
0
def _judge(submission_id, time_limit, memory_limit, test_case_id):
    judge.delay(submission_id, time_limit, memory_limit, test_case_id)
    get_cache_redis().incr("judge_queue_length")
コード例 #6
0
ファイル: views.py プロジェクト: kdwycz/OnlineJudge
def _judge(submission_id, time_limit, memory_limit, test_case_id):
    judge.delay(submission_id, time_limit, memory_limit, test_case_id)
    get_cache_redis().incr("judge_queue_length")