【发布时间】:2016-08-10 08:01:49
【问题描述】:
我对要使用 Celery 执行的数据库有一些“繁重”的请求。考虑到它们很“重”,我想按顺序(一个接一个)执行它们。一种可能的解决方案是在 Celery 的命令行中指定 --concurrency=1。它有效。但是有一个问题:在执行任务时,以下所有请求都返回None:
from celery.task.control import inspect
# Inspect all nodes.
i = inspect()
print(i.scheduled()) # None
print(i.active()) # None
print(i.reserved()) # None
print(i.registered()) # None
另外,运行celery inspect ping 会返回Error: No nodes replied within time constraint.,这样我就无法收到有关 Celery 队列状态的任何信息。
有我的测试python模块:
celeryconfig.py
#BROKER_URL = 'redis://localhost:6379/0'
BROKER_URL = 'amqp://'
#CELERY_RESULT_BACKEND = "redis"
CELERY_RESULT_BACKEND = "amqp://"
# for php
CELERY_TASK_RESULT_EXPIRES = None
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_ACKS_LATE = True
tasks.py
from celery import Celery
from time import sleep
app = Celery('hello')
app.config_from_object('celeryconfig')
@app.task
def add(x, y):
sleep(30)
return x + y
client.py
from tasks import add
result=add.delay(4, 4)
result=add.delay(4, 4)
result=add.delay(4, 4)
result=add.delay(4, 4)
result=add.delay(4, 4)
result=add.delay(4, 4)
那么,问题来了,如何一个一个地运行任务并且能够检查队列的状态?
【问题讨论】: