2015-08-15 06:50:22 +00:00
|
|
|
# coding=utf-8
|
2015-08-22 04:56:22 +00:00
|
|
|
import json
|
2015-08-19 08:39:04 +00:00
|
|
|
import redis
|
2015-08-17 04:48:10 +00:00
|
|
|
import MySQLdb
|
2015-08-15 09:49:51 +00:00
|
|
|
import subprocess
|
2015-08-15 06:50:22 +00:00
|
|
|
from ..judger.result import result
|
|
|
|
from ..judger_controller.celery import app
|
2015-09-12 11:21:43 +00:00
|
|
|
from settings import docker_config, source_code_dir, test_case_dir, log_dir, submission_db, redis_config
|
2015-08-15 06:50:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.task
|
|
|
|
def judge(submission_id, time_limit, memory_limit, test_case_id):
|
|
|
|
try:
|
2015-09-17 03:18:38 +00:00
|
|
|
command = "%s run --privileged --rm " \
|
2015-09-15 08:35:39 +00:00
|
|
|
"--link mysql " \
|
2015-09-25 05:10:09 +00:00
|
|
|
"-v %s:/var/judger/test_case/:ro " \
|
2015-09-25 07:05:17 +00:00
|
|
|
"-v %s:/var/judger/code/:ro " \
|
2015-09-12 11:21:43 +00:00
|
|
|
"-v %s:/var/judger/code/log/ " \
|
2015-09-25 05:10:09 +00:00
|
|
|
"--device /dev/null:/dev/null " \
|
2015-08-15 06:50:22 +00:00
|
|
|
"%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,
|
2015-09-12 11:21:43 +00:00
|
|
|
log_dir,
|
2015-08-15 06:50:22 +00:00
|
|
|
docker_config["image_name"],
|
|
|
|
submission_id, str(time_limit), str(memory_limit), test_case_id)
|
2015-08-15 09:52:07 +00:00
|
|
|
subprocess.call(command, shell=docker_config["shell"])
|
2015-08-15 06:50:22 +00:00
|
|
|
except Exception as e:
|
2015-08-17 04:48:10 +00:00
|
|
|
conn = MySQLdb.connect(db=submission_db["db"],
|
|
|
|
user=submission_db["user"],
|
|
|
|
passwd=submission_db["password"],
|
|
|
|
host=submission_db["host"],
|
|
|
|
port=submission_db["port"],
|
2015-09-18 13:48:54 +00:00
|
|
|
charset="utf8")
|
2015-08-17 04:48:10 +00:00
|
|
|
|
|
|
|
cur = conn.cursor()
|
|
|
|
cur.execute("update submission set result=%s, info=%s where id=%s",
|
|
|
|
(result["system_error"], str(e), submission_id))
|
|
|
|
conn.commit()
|
2015-08-21 05:25:30 +00:00
|
|
|
conn.close()
|
2015-08-21 05:32:02 +00:00
|
|
|
r = redis.Redis(host=redis_config["host"], port=redis_config["port"], db=redis_config["db"])
|
2015-08-22 04:31:28 +00:00
|
|
|
r.decr("judge_queue_length")
|
|
|
|
r.lpush("queue", submission_id)
|