Celery task history

时间秒杀一切 提交于 2019-12-22 06:56:46

问题


I am building a framework for executing tasks on top of Celery framework.

I would like to see the list of recently executed tasks (for the recent 2-7 days).

Looking on the API I can find app.backend object, but cannot figure out how to make a query to fetch tasks.

For example I can use backends like Redis or database. I do not want to explicitly write SQL queries to database.

Is there a way to work with task history/results with API?

I tried to use Flower, but it can only handle events and cannot get history before its start.


回答1:


You need to keep the task results in a backend, for example Redis. The Celery documentation contains information about how to do this here:

http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html#keeping-results

Also you want to set the CELERY_TASK_RESULT_EXPIRES configuration parameter, because by default the results are discarded after one day.

If you do this, then Flower will show you the history of the task execution, irregardless from when it started.




回答2:


You can use the persisent option,eg: flower -A ctq.celery --persistent=True



来源:https://stackoverflow.com/questions/35726948/celery-task-history

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!