Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Celery task history

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.

like image 969
baldr Avatar asked Mar 01 '16 15:03

baldr


People also ask

How do you check Celery logs?

Celery have specific option -f --logfile which you can use: -f LOGFILE, --logfile=LOGFILE Path to log file.

How do I check my Celery queue?

Just to spell things out, the DATABASE_NUMBER used by default is 0 , and the QUEUE_NAME is celery , so redis-cli -n 0 llen celery will return the number of queued messages.


2 Answers

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

like image 66
杨冠宇 Avatar answered Sep 30 '22 05:09

杨冠宇


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, regardless from when it started.

like image 37
mavroprovato Avatar answered Sep 30 '22 06:09

mavroprovato