修改判题的目录结构
This commit is contained in:
1
judge/judger_controller/README.md
Normal file
1
judge/judger_controller/README.md
Normal file
@@ -0,0 +1 @@
|
||||
celery -A judge.controller worker -l DEBUG
|
||||
1
judge/judger_controller/__init__.py
Normal file
1
judge/judger_controller/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# coding=utf-8
|
||||
10
judge/judger_controller/celery.py
Normal file
10
judge/judger_controller/celery.py
Normal file
@@ -0,0 +1,10 @@
|
||||
# coding=utf-8
|
||||
from __future__ import absolute_import
|
||||
from celery import Celery
|
||||
from .settings import redis_config
|
||||
|
||||
app = Celery("judge", broker="redis://" +
|
||||
redis_config["host"] + ":" +
|
||||
str(redis_config["port"]) +
|
||||
"/" + str(redis_config["db"]),
|
||||
include=["judge.judger_controller.tasks"])
|
||||
25
judge/judger_controller/settings.py
Normal file
25
judge/judger_controller/settings.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# coding=utf-8
|
||||
redis_config = {
|
||||
"host": "127.0.0.1",
|
||||
"port": 6379,
|
||||
"db": 0
|
||||
}
|
||||
|
||||
|
||||
docker_config = {
|
||||
"image_name": "judger",
|
||||
"docker_path": "docker",
|
||||
"shell": True
|
||||
}
|
||||
|
||||
|
||||
test_case_dir = "/Users/virusdefender/Desktop/test_case/"
|
||||
source_code_dir = "/Users/virusdefender/Desktop/"
|
||||
|
||||
|
||||
mongodb_config = {
|
||||
"host": "192.168.59.3",
|
||||
"username": "root",
|
||||
"password": "root",
|
||||
"port": 27017
|
||||
}
|
||||
31
judge/judger_controller/tasks.py
Normal file
31
judge/judger_controller/tasks.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# coding=utf-8
|
||||
# from __future__ import absolute_import
|
||||
import pymongo
|
||||
from bson import ObjectId
|
||||
import subprocess32 as subprocess
|
||||
from ..judger.result import result
|
||||
from ..judger_controller.celery import app
|
||||
from settings import docker_config, source_code_dir, test_case_dir, mongodb_config
|
||||
|
||||
|
||||
@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)
|
||||
subprocess.call(command, timeout=(time_limit / 1000.0 * 10), shell=docker_config["shell"])
|
||||
except Exception as e:
|
||||
connection = pymongo.MongoClient(host=mongodb_config["host"], port=mongodb_config["port"])
|
||||
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()
|
||||
Reference in New Issue
Block a user