修改判题数据库
This commit is contained in:
@@ -4,6 +4,4 @@ from celery import Celery
|
||||
from .settings import redis_config
|
||||
|
||||
app = Celery("judge", broker='redis://%s:%s/%s' % (redis_config["host"], redis_config["port"], redis_config["db"]),
|
||||
include=["judge.judger_controller.tasks"])
|
||||
|
||||
Celery().conf.update(CELERY_ACCEPT_CONTENT = ['json'])
|
||||
include=["judge.judger_controller.tasks"])
|
||||
@@ -7,7 +7,7 @@ redis_config = {
|
||||
|
||||
|
||||
docker_config = {
|
||||
"image_name": "d622347336b8",
|
||||
"image_name": " a7673b55d263",
|
||||
"docker_path": "docker",
|
||||
"shell": True
|
||||
}
|
||||
@@ -17,16 +17,10 @@ test_case_dir = "/root/test_case/"
|
||||
source_code_dir = "/root/"
|
||||
|
||||
|
||||
celery_mongodb_config = {
|
||||
submission_db = {
|
||||
"host": "127.0.0.1",
|
||||
"username": "root",
|
||||
"password": "root",
|
||||
"port": 27017
|
||||
}
|
||||
|
||||
docker_mongodb_config = {
|
||||
"host": "192.168.42.1",
|
||||
"username": "root",
|
||||
"password": "root",
|
||||
"port": 27017
|
||||
"port": 3306,
|
||||
"db": "oj_submission",
|
||||
"user": "root",
|
||||
"password": "root"
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
# coding=utf-8
|
||||
# from __future__ import absolute_import
|
||||
import MySQLdb
|
||||
import subprocess
|
||||
import pymongo
|
||||
from bson import ObjectId
|
||||
from ..judger.result import result
|
||||
from ..judger_controller.celery import app
|
||||
from settings import docker_config, source_code_dir, test_case_dir, celery_mongodb_config
|
||||
from settings import docker_config, source_code_dir, test_case_dir, submission_db
|
||||
|
||||
|
||||
@app.task
|
||||
@@ -24,8 +23,16 @@ def judge(submission_id, time_limit, memory_limit, test_case_id):
|
||||
submission_id, str(time_limit), str(memory_limit), test_case_id)
|
||||
subprocess.call(command, shell=docker_config["shell"])
|
||||
except Exception as e:
|
||||
connection = pymongo.MongoClient(host=celery_mongodb_config["host"], port=celery_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()
|
||||
print e
|
||||
conn = MySQLdb.connect(db=submission_db["db"],
|
||||
user=submission_db["user"],
|
||||
passwd=submission_db["password"],
|
||||
host=submission_db["host"],
|
||||
port=submission_db["port"],
|
||||
character="utf8")
|
||||
|
||||
cur = conn.cursor()
|
||||
cur.execute("update submission set result=%s, info=%s where id=%s",
|
||||
(result["system_error"], str(e), submission_id))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
Reference in New Issue
Block a user