celery task clean-up with DB backend

Keith picture Keith · Oct 30, 2012 · Viewed 10.3k times · Source

I'm trying to understand how and when tasks are cleaned up in celery. From looking at the task docs I see that:

Old results will be cleaned automatically, based on the CELERY_TASK_RESULT_EXPIRES setting. By default this is set to expire after 1 day: if you have a very busy cluster you should lower this value.

But this quote is from the RabbitMQ Result Backend section and I do not see any similar text in the Database Backend section. So my question is: is there a backend agnostic approach I can take for old task clean-up with celery and if not is there a DB Backend specific approach I should take? Incase it makes any difference I'm using django-celery. Thanks.

Answer

asksol picture asksol · Oct 31, 2012

If you click on the link to the setting doc for CELERY_TASK_RESULT_EXPIRES:

http://docs.celeryproject.org/en/latest/userguide/configuration.html#result-expires

It does say that database supports this, but then you need to run celery beat (there's a default periodic task, called every day, to remove expired results).

The backend docs in the task should probably mention this as well, maybe there should be a dedicated guide for backends too. If you want to lobby for this, then please open up an issue at https://github.com/celery/celery/issues