我需要配置芹菜队列应该放置任务执行结果,我使用这种方式described in documentation(项目“reply_to”):
@app.task(reply_to='export_task') # <= configured right way
def test_func():
return "here is result of task"
预期行为
任务结果应该在队列中,名称为“export_task”(在装饰器中配置)
实际行为
任务结果位于队列中,名称如下: d5587446-0149-3133-a3ed-d9a297d52a96
芹菜报道:
python -m celery -A my_worker report
software -> celery:3.1.24 (Cipater) kombu:3.0.37 py:3.5.1
billiard:3.3.0.23 py-amqp:1.4.9
platform -> system:Windows arch:64bit, WindowsPE imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:amqp results:rpc:///
CELERY_ACCEPT_CONTENT: ['json']
CELERY_RESULT_BACKEND: 'rpc:///'
CELERY_QUEUES:
(<unbound Queue main_check -> <unbound Exchange main_check(direct)> -> main_check>,)
CELERYD_CONCURRENCY: 10
CELERY_TASK_SERIALIZER: 'json'
CELERY_RESULT_PERSISTENT: True
CELERY_ROUTES: {
'my_worker.test_func': {'queue': 'main_check'}}
BROKER_TRANSPORT: 'amqp'
CELERYD_MAX_TASKS_PER_CHILD: 3
CELERY_RESULT_SERIALIZER: 'json'
重现的步骤
请创建项目文件。
celery_app.py :
from celery import Celery
from kombu import Exchange, Queue
app = Celery('worker')
app.conf.update(
CELERY_ROUTES={
'my_worker.test_func': {'queue': 'main_check'},
},
BROKER_TRANSPORT='amqp',
CELERY_RESULT_BACKEND='rpc://',
CELERY_RESULT_PERSISTENT=True,
# CELERY_DEFAULT_DELIVERY_MODE='persistent',
# CELERY_RESULT_EXCHANGE='export_task',
CELERYD_CONCURRENCY=10,
CELERYD_MAX_TASKS_PER_CHILD=3,
CELERY_TASK_SERIALIZER='json',
CELERY_RESULT_SERIALIZER='json',
CELERY_ACCEPT_CONTENT=['json'],
CELERY_QUEUES=(
Queue('main_check', Exchange('main_check', type='direct'), routing_key='main_check'),
),
)
my_worker.py:
from celery_app import app
@app.task(reply_to='export_task')
def test_func():
return "here is result of task"
然后开始芹菜:
python -m celery -A my_worker worker --loglevel=info
然后在python调试控制台中添加新任务:
from my_worker import *
result = test_func.delay()
我要求official issue tracker提供帮助,但没有人关心。
答案 0 :(得分:0)
我在代码中没有看到已声明该队列(export_task)的位置。