OnlineJudge/judge/judger_controller/tasks.py

32 lines
1.4 KiB
Python
Raw Normal View History

2015-08-15 06:50:22 +00:00
# coding=utf-8
# from __future__ import absolute_import
2015-08-15 09:49:51 +00:00
import subprocess
2015-08-15 06:50:22 +00:00
import pymongo
from bson import ObjectId
from ..judger.result import result
from ..judger_controller.celery import app
2015-08-15 09:02:46 +00:00
from settings import docker_config, source_code_dir, test_case_dir, celery_mongodb_config
2015-08-15 06:50:22 +00:00
@app.task
def judge(submission_id, time_limit, memory_limit, test_case_id):
try:
command = "%s run -t -i --privileged --rm=true " \
"-v %s:/var/judger/test_case/ " \
"-v %s:/var/judger/code/ " \
"%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,
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-15 09:02:46 +00:00
connection = pymongo.MongoClient(host=celery_mongodb_config["host"], port=celery_mongodb_config["port"])
2015-08-15 06:50:22 +00:00
collection = connection["oj"]["oj_submission"]
data = {"result": result["system_error"], "info": str(e)}
collection.find_one_and_update({"_id": ObjectId(submission_id)}, {"$set": data})
connection.close()