修正错误的celery配置

This commit is contained in:
virusdefender 2016-05-03 13:26:23 +08:00
parent 2c9e799e45
commit e05c5a284e
No known key found for this signature in database
GPG Key ID: 1686FB5677979E61
5 changed files with 16 additions and 43 deletions

View File

@ -21,8 +21,9 @@ DATABASES = {
}
}
REDIS_LOCAL_QUEUE = {
REDIS_QUEUE = {
"host": "127.0.0.1",
"port": 6379,
"db": 3
"db": 3,
"password": ":" + os.environ["REDIS_PASSWORD"] + "@"
}

View File

@ -26,7 +26,7 @@ DATABASES = {
}
}
REDIS_LOCAL_QUEUE = {
REDIS_QUEUE = {
"host": os.environ["REDIS_PORT_6379_TCP_ADDR"],
"port": 6379,
"db": 3,

View File

@ -117,18 +117,18 @@ STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
BROKER_URL = "redis://{password}{host}:{port}/{db}".format(password=REDIS_LOCAL_QUEUE.get("password", ""),
host=REDIS_LOCAL_QUEUE["host"],
port=REDIS_LOCAL_QUEUE["port"],
db=REDIS_LOCAL_QUEUE["db"])
CELERY_RESULT_BACKEND = "redis"
CELERY_RESULT_BACKEND = BROKER_URL = "redis://{password}{host}:{port}/{db}".format(
password=REDIS_QUEUE.get("password", ""),
host=REDIS_QUEUE["host"],
port=REDIS_QUEUE["port"],
db=REDIS_QUEUE["db"])
CELERY_ROUTES = {
'server.tasks.submit_dispatcher': {'queue': 'local'},
'server.tasks.submit_waiting_submission': {'queue': 'local'},
'server.tasks.update_submission': {'queue': 'local'},
'server.tasks.get_problem': {'queue': 'robot'},
'server.tasks.submit': {'queue': 'robot'},
'robot.tasks.get_problem': {'queue': 'robot'},
'robot.tasks.submit': {'queue': 'robot'},
}
LOGGING = {

View File

@ -2,37 +2,9 @@
import time
import os
from celery import Celery
from openvj import celery_app as app
from .utils import Result
if os.environ.get("robot_env", "local") == "local":
REDIS_ROBOT_QUEUE = {
"host": "127.0.0.1",
"port": 6379,
"db": 3
}
else:
REDIS_ROBOT_QUEUE = {
"host": os.environ["REDIS_PORT_6379_TCP_ADDR"],
"port": 6379,
"db": 3,
"password": os.environ["REDIS_PASSWORD"]
}
def _redis_password():
password = REDIS_ROBOT_QUEUE.get("password")
if password:
return password + "@"
else:
return ""
app = Celery('tasks', broker="redis://{password}{host}:{port}/{db}".format(password=_redis_password(),
host=REDIS_ROBOT_QUEUE["host"],
port=REDIS_ROBOT_QUEUE["port"],
db=REDIS_ROBOT_QUEUE["db"]))
# remote robot task
@app.task

View File

@ -3,7 +3,7 @@ from __future__ import absolute_import
import time
import json
from openvj import celery_app
from openvj import celery_app as app
from robots.tasks import submit, get_problem
from .models import RobotUserStatus, SubmissionStatus, SubmissionWaitingQueue
@ -14,7 +14,7 @@ def release_robot_user(robot_user):
# local task
@celery_app.task
@app.task
def submit_waiting_submission(submit_result, problem, robot, robot_user):
waiting_queue = SubmissionWaitingQueue.objects.all().order_by("create_time")
if waiting_queue.exists():
@ -29,7 +29,7 @@ def submit_waiting_submission(submit_result, problem, robot, robot_user):
# local task
@celery_app.task
@app.task
def update_submission(submit_result, submission):
submission.origin_submission_id = submit_result["origin_submission_id"]
submission.result = submit_result["result"]
@ -41,7 +41,7 @@ def update_submission(submit_result, submission):
# local task
@celery_app.task
@app.task
def submit_dispatcher(problem, submission, robot_user, robot):
task_id = submit.apply_async(args=(robot, robot_user, problem.submit_url, problem.origin_id,
submission.language, submission.code),