From 096873c02812f2319c6768ee3c08ad1ffea5428c Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Wed, 19 Aug 2015 16:39:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=98=9F=E5=88=97=E9=95=BF?= =?UTF-8?q?=E5=BA=A6=E7=BB=9F=E8=AE=A1=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- judge/judger_controller/tasks.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/judge/judger_controller/tasks.py b/judge/judger_controller/tasks.py index e8066892..e61da72b 100644 --- a/judge/judger_controller/tasks.py +++ b/judge/judger_controller/tasks.py @@ -1,14 +1,21 @@ # coding=utf-8 -# from __future__ import absolute_import +import datetime +import redis import MySQLdb import subprocess from ..judger.result import result from ..judger_controller.celery import app -from settings import docker_config, source_code_dir, test_case_dir, submission_db +from settings import docker_config, source_code_dir, test_case_dir, submission_db, redis_config @app.task def judge(submission_id, time_limit, memory_limit, test_case_id): + # 先更新判题队列长度 + r = redis.StrictRedis(host=redis_config["host"], port=redis_config["port"], db=redis_config["db"]) + length = r.incr("queue_length") + now = datetime.datetime.now() + # 使用hash key是今天的日期 value 的 key 是当前时分秒 12:02:03 value 是队列长度 + r.hset(str(datetime.date.today()), ":".join([str(now.hour), str(now.minute), str(now.second)]), length) try: command = "%s run -t -i --privileged --rm=true " \ "-v %s:/var/judger/test_case/ " \ @@ -36,3 +43,7 @@ def judge(submission_id, time_limit, memory_limit, test_case_id): (result["system_error"], str(e), submission_id)) conn.commit() conn.close() + r.decr("queue_length") + now = datetime.datetime.now() + # 使用hash key是今天的日期 value 的 key 是当前时分秒 12:02:03 value 是队列长度 + r.hset(str(datetime.date.today()), ":".join([str(now.hour), str(now.minute), str(now.second)]), length)