增加判题中的日志记录,没有测试

This commit is contained in:
virusdefender
2015-09-12 19:21:43 +08:00
parent ee9951abf1
commit 1dc0e8b742
11 changed files with 47 additions and 217 deletions

View File

@@ -0,0 +1,9 @@
# coding=utf-8
import logging
# 此处的 celery 代码如果在 docker 中运行需要将filename 修改为映射路径
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s [%(threadName)s:%(thread)d] [%(name)s:%(lineno)d] [%(module)s:%(funcName)s] [%(levelname)s]- %(message)s',
filename='/var/log/judge.log')
logger = logging

View File

@@ -19,6 +19,8 @@ docker_config = {
test_case_dir = "/var/mnt/source/test_case/"
# 源代码路径,也就是 manage.py 所在的实际路径
source_code_dir = "/var/mnt/source/OnlineJudge/"
# 日志文件夹路径
log_dir = "/var/log/"
# 存储提交信息的数据库,是 celery 使用的,与 oj.settings/local_settings 等区分,那是 web 服务器访问的地址

View File

@@ -5,7 +5,8 @@ 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, redis_config
from logger import logger
from settings import docker_config, source_code_dir, test_case_dir, log_dir, submission_db, redis_config
@app.task
@@ -14,17 +15,19 @@ def judge(submission_id, time_limit, memory_limit, test_case_id):
command = "%s run -t -i --privileged --rm=true " \
"-v %s:/var/judger/test_case/ " \
"-v %s:/var/judger/code/ " \
"-v %s:/var/judger/code/log/ " \
"%s " \
"python judge/judger/run.py " \
"--solution_id %s --time_limit %s --memory_limit %s --test_case_id %s" % \
(docker_config["docker_path"],
test_case_dir,
source_code_dir,
log_dir,
docker_config["image_name"],
submission_id, str(time_limit), str(memory_limit), test_case_id)
subprocess.call(command, shell=docker_config["shell"])
except Exception as e:
print e
logger.error(e)
conn = MySQLdb.connect(db=submission_db["db"],
user=submission_db["user"],
passwd=submission_db["password"],