我已经开始使用芹菜:
celery -A tasks worker --loglevel=info
然后使用以下命令启动python应用程序:
python app.py
当我要检查AsycnResults时,在app.py中:
for id in task_id.keys():
st[id] = str(AsyncResult(id).state)
它会引发错误消息:
Traceback (most recent call last):
File "<...>/app.py", line 271, in update_task_status
**st[id] = str(AsyncResult(id).state)**
File "../anaconda3/lib/python3.7/site-packages/celery/result.py", line 473, in state
return self._get_task_meta()['status']
File "<...>/anaconda3/lib/python3.7/site-packages/celery/result.py", line 412, in _get_task_meta
return self._maybe_set_cache(self.backend.get_task_meta(self.id))
File "<...>/anaconda3/lib/python3.7/site-packages/celery/backends/base.py", line 386, in get_task_meta
meta = self._get_task_meta_for(task_id)
AttributeError: 'DisabledBackend' object has no attribute '_get_task_meta_for'
但是当我使用heroku启动应用程序和celery时,它运行正常:
heroku local
<and the Procfile is like>
web: gunicorn -b 0.0.0.0:8000 app:server --log-file=-
worker: celery -A tasks worker --loglevel=info
奇怪的是,当我想在heroku local下设置更多的worker /线程时,它再次给出相同的错误。
<heroku local's Procfile>
web: gunicorn --workers 6 --threads 2 -b 0.0.0.0:11000 app:server --log-file=-
#web: gunicorn -b 0.0.0.0:11000 app:server --log-file=-
worker: celery -A tasks worker --loglevel=info
在这两种情况下,芹菜似乎都可以正常工作,并且可以接收和处理消息:
[tasks]
. tasks.query_adj_info
. tasks.query_perf_by
. tasks.query_perf_dai
. tasks.query_perf_sum
[2019-07-03 21:56:59,539: INFO/MainProcess] Connected to redis://0.0.0.0:6379//
[2019-07-03 21:56:59,549: INFO/MainProcess] mingle: searching for neighbors
[2019-07-03 21:57:00,573: INFO/MainProcess] mingle: all alone
[2019-07-03 21:57:00,582: INFO/MainProcess] celery@r ready.
[2019-07-03 21:58:57,779: INFO/MainProcess] Received task: tasks.query[depid_eddd6a1a-610f-484f-b2fa-f3052e0c910b_celtid_perfa616b950-e7b8-4c5b-9d80-dc9907796be8]
[2019-07-03 21:58:57,780: INFO/MainProcess] Received task: ....
答案 0 :(得分:0)
检查您是否已配置后端
app = Celery('proj', backend='amqp://', broker='amqp://guest@localhost//')
如果您使用django,请尝试使用python manage.py shell
而非仅使用python
。我在纯python shell上的芹菜后端遇到问题。