celeryconfig.py
配置如下:
from datetime import timedelta
BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULT_BACKEND = "redis"
CELERY_REDIS_HOST = "localhost"
CELERY_REDIS_PORT = 6379
CELERY_REDIS_DB = 0
CELERY_IMPORTS=("mytasks")
CELERYBEAT_SCHEDULE={'runs-every-60-seconds' :
{
'task': 'mytasks.add',
'schedule': timedelta(seconds=60),
'args':(16,16)
},
}
和mytask.py
如下:
from celery import Celery
celery = Celery("tasks",
broker='redis://localhost:6379/0',
backend='redis')
@celery.task
def add(x,y):
return x+y
@celery.task
def mul(x,y):
return x*y
我跑步的时候
celery beat -s celerybeat-schedule
然后我正在
Configuration ->
. broker -> redis://localhost:6379/0
. loader -> celery.loaders.default.Loader
. scheduler -> celery.beat.PersistentScheduler
. db -> celerybeat-schedule
. logfile -> [stderr]@INFO
. maxinterval -> now (0s)
[2012-08-28 12:27:17,825: INFO/MainProcess] Celerybeat: Starting...
[2012-08-28 12:28:00,041: INFO/MainProcess] Scheduler: Sending due task mytasks.add
[2012-08-28 12:29:00,057: INFO/MainProcess] Scheduler: Sending due task mytasks.add
[2012-08-28 12:30:00,064: INFO/MainProcess] Scheduler: Sending due task mytasks.add
[2012-08-28 12:31:00,097: INFO/MainProcess] Scheduler: Sending due task mytasks.add
现在我没有得到我已经通过参数(16,16)
然后我如何得到这个函数的答案add(x,y)
答案 0 :(得分:4)
我不确定我完全明白你的要求,但据我所知,你的问题可能是以下之一:
1)你在运行celeryd(工作守护程序)吗?如果没有,你是否在码头开了一个芹菜工人?芹菜击败是task scheduler。它不是worker。 Celerybeat仅调度任务(即将它们放入队列中以供工人最终消费)。
2)您是如何计划查看结果的?他们被保存在某个地方吗?由于您已将结果后端设置为redis,因此结果至少会临时存储在redis results backend
中