diff --git a/judge/judger/run.py b/judge/judger/run.py index f93a4f84..f13673ee 100644 --- a/judge/judger/run.py +++ b/judge/judger/run.py @@ -13,7 +13,7 @@ from settings import judger_workspace sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/' + '..')) -from judger_controller.settings import mongodb_config +from judger_controller.settings import celery_mongodb_config, docker_mongodb_config # 简单的解析命令行参数 @@ -25,7 +25,7 @@ time_limit = args[4] memory_limit = args[6] test_case_id = args[8] -connection = pymongo.MongoClient(host=mongodb_config["host"], port=mongodb_config["port"]) +connection = pymongo.MongoClient(host=docker_mongodb_config["host"], port=docker_mongodb_config["port"]) collection = connection["oj"]["oj_submission"] submission = collection.find_one({"_id": ObjectId(submission_id)}) @@ -45,7 +45,7 @@ try: exe_path = compile_(language, src_path, judger_workspace + "run/") except Exception as e: print e - connection = pymongo.MongoClient(host=mongodb_config["host"], port=mongodb_config["port"]) + connection = pymongo.MongoClient(host=docker_mongodb_config["host"], port=docker_mongodb_config["port"]) collection = connection["oj"]["oj_submission"] data = {"result": result["compile_error"], "info": str(e)} collection.find_one_and_update({"_id": ObjectId(submission_id)}, {"$set": data}) @@ -77,7 +77,7 @@ except Exception as e: print "Run successfully" print judge_result -connection = pymongo.MongoClient(host=mongodb_config["host"], port=mongodb_config["port"]) +connection = pymongo.MongoClient(host=docker_mongodb_config["host"], port=docker_mongodb_config["port"]) collection = connection["oj"]["oj_submission"] collection.find_one_and_update({"_id": ObjectId(submission_id)}, {"$set": judge_result}) connection.close() diff --git a/judge/judger_controller/settings.py b/judge/judger_controller/settings.py index 74761497..79648324 100644 --- a/judge/judger_controller/settings.py +++ b/judge/judger_controller/settings.py @@ -1,24 +1,31 @@ # coding=utf-8 redis_config = { - "host": "127.0.0.1", + "host": "121.42.196.141", "port": 6379, "db": 0 } docker_config = { - "image_name": "judger", + "image_name": "d622347336b8", "docker_path": "docker", "shell": True } -test_case_dir = "/Users/virusdefender/Desktop/test_case/" -source_code_dir = "/Users/virusdefender/Desktop/" +test_case_dir = "/root/test_case/" +source_code_dir = "/root/" -mongodb_config = { - "host": "192.168.59.3", +celery_mongodb_config = { + "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 diff --git a/oj/local_settings.py b/oj/local_settings.py index 2112566d..7963e7a0 100644 --- a/oj/local_settings.py +++ b/oj/local_settings.py @@ -16,8 +16,9 @@ DATABASES = { } } +# 这是web 服务器连接到mongodb 的地址 MONGODB = { - 'HOST': '127.0.0.1', + 'HOST': '121.42.196.141', 'USERNAME': 'root', 'PASSWORD': 'root', 'PORT': 27017 @@ -26,4 +27,4 @@ MONGODB = { DEBUG = True # 同理 这是 web 服务器的上传路径 -TEST_CASE_DIR = "/Users/virusdefender/Desktop/test_case/" +TEST_CASE_DIR = os.path.join(BASE_DIR, 'test_case') diff --git a/submission/views.py b/submission/views.py index b0d9794d..53867728 100644 --- a/submission/views.py +++ b/submission/views.py @@ -14,7 +14,7 @@ from judge.judger_controller.tasks import judge from account.decorators import login_required from problem.models import Problem from utils.shortcuts import serializer_invalid_response, error_response, success_response, error_page -from .serializers import CreateSubmissionSerializer +from .serializers import CreateSubmissionSerializer def _create_mongodb_connection():