我正在演示,代码很简单:
# tasks.py
import time
from celery import Celery
app = Celery('tasks',
broker='redis://:5tgb^YHN7ujm*IK<@localhost:6379/0',
backend='redis://:5tgb^YHN7ujm*IK<@localhost:6379/0'
)
@app.task
def test_task(s):
time.sleep(300)
return s
然后启动工作人员
celery -A celery_test.app worker -n kalidog -c 2 -l debug -E
-------------- celery@kalidog v4.3.0 (rhubarb)
---- **** -----
--- * *** * -- Linux-4.9.0-8-amd64-x86_64-with-debian-9.8 2019-10-11 02:36:12
-- * - **** ---
- ** ---------- [config]
- ** ---------- .> app: tasks:0x7f17bf92e128
- ** ---------- .> transport: redis://:**@localhost:6379/0
- ** ---------- .> results: redis://:**@localhost:6379/0
- *** --- * --- .> concurrency: 2 (prefork)
-- ******* ---- .> task events: ON
--- ***** -----
-------------- [queues]
.> celery exchange=celery(direct) key=celery
然后安排任务:
>>>from celery_test import test_task
>>>result = test_task.apply_async((11,))
>>>result.status
'PENDING'
>>>result.state
'PENDING'
>>>result.state
'PENDING'
>>>result.state
'SUCCESS'
为什么任务状态中没有“开始”?我检查了redis。在任务完成之前,redis中没有当前任务的密钥,例如“ celery-task-meta-XXX”。
答案 0 :(得分:2)
默认情况下不启用该功能。有关更多信息,请访问:https://docs.celeryproject.org/en/latest/userguide/tasks.html#started