mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-09-21 00:13:18 +00:00
修改判题的目录结构
This commit is contained in:
parent
025335b40a
commit
cb7dd2f820
@ -1,5 +1,6 @@
|
|||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
import pymongo
|
import pymongo
|
||||||
|
|
||||||
from bson.objectid import ObjectId
|
from bson.objectid import ObjectId
|
||||||
@ -8,7 +9,11 @@ from client import JudgeClient
|
|||||||
from language import languages
|
from language import languages
|
||||||
from compiler import compile_
|
from compiler import compile_
|
||||||
from result import result
|
from result import result
|
||||||
from settings import judger_workspace, mongodb_config
|
from settings import judger_workspace
|
||||||
|
|
||||||
|
sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/' + '..'))
|
||||||
|
|
||||||
|
from judger_controller.settings import mongodb_config
|
||||||
|
|
||||||
|
|
||||||
# 简单的解析命令行参数
|
# 简单的解析命令行参数
|
||||||
@ -76,6 +81,3 @@ connection = pymongo.MongoClient(host=mongodb_config["host"], port=mongodb_confi
|
|||||||
collection = connection["oj"]["oj_submission"]
|
collection = connection["oj"]["oj_submission"]
|
||||||
collection.find_one_and_update({"_id": ObjectId(submission_id)}, {"$set": judge_result})
|
collection.find_one_and_update({"_id": ObjectId(submission_id)}, {"$set": judge_result})
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -14,9 +14,4 @@ lrun_gid = 1002
|
|||||||
# judger工作目录
|
# judger工作目录
|
||||||
judger_workspace = "/var/judger/"
|
judger_workspace = "/var/judger/"
|
||||||
|
|
||||||
mongodb_config = {
|
|
||||||
"host": "192.168.59.3",
|
|
||||||
"username": "root",
|
|
||||||
"password": "root",
|
|
||||||
"port": 27017
|
|
||||||
}
|
|
@ -7,4 +7,4 @@ app = Celery("judge", broker="redis://" +
|
|||||||
redis_config["host"] + ":" +
|
redis_config["host"] + ":" +
|
||||||
str(redis_config["port"]) +
|
str(redis_config["port"]) +
|
||||||
"/" + str(redis_config["db"]),
|
"/" + str(redis_config["db"]),
|
||||||
include=["judger_controller.tasks"])
|
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()
|
@ -1,6 +0,0 @@
|
|||||||
# coding=utf-8
|
|
||||||
redis_config = {
|
|
||||||
"host": "127.0.0.1",
|
|
||||||
"port": 6379,
|
|
||||||
"db": 0
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
# coding=utf-8
|
|
||||||
from __future__ import absolute_import
|
|
||||||
from judger_controller.celery import app
|
|
||||||
import subprocess32 as subprocess
|
|
||||||
|
|
||||||
|
|
||||||
@app.task
|
|
||||||
def judge(solution_id, time_limit, memory_limit, test_case_id):
|
|
||||||
try:
|
|
||||||
subprocess.call("docker run -t -i --privileged --rm=true "
|
|
||||||
"-v /Users/virusdefender/Desktop/test_case/:/var/judger/test_case/ "
|
|
||||||
"-v /Users/virusdefender/Desktop/:/var/judger/code/ "
|
|
||||||
"judger "
|
|
||||||
"python judger/run.py "
|
|
||||||
"--solution_id %s --time_limit %s --memory_limit %s --test_case_id %s" %
|
|
||||||
(solution_id, str(time_limit), str(memory_limit), test_case_id),
|
|
||||||
# 设置最长运行时间是5倍的 cpu 时间
|
|
||||||
timeout=(time_limit / 1000.0 * 5), shell=True)
|
|
||||||
except subprocess.TimeoutExpired:
|
|
||||||
print "docker timeout"
|
|
@ -9,8 +9,8 @@ from rest_framework.views import APIView
|
|||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from judger.result import result
|
from judge.judger.result import result
|
||||||
from judger_controller.tasks import judge
|
from judge.judger_controller.tasks import judge
|
||||||
from account.decorators import login_required
|
from account.decorators import login_required
|
||||||
from problem.models import Problem
|
from problem.models import Problem
|
||||||
from utils.shortcuts import serializer_invalid_response, error_response, success_response, error_page
|
from utils.shortcuts import serializer_invalid_response, error_response, success_response, error_page
|
||||||
|
Loading…
Reference in New Issue
Block a user