How can I recover celery tasks that haven't started yet using Django?

From reading the herring documentation , it looks like I have to use the following python code to list the tasks in the queue that have not yet been raised:

from celery.task.control import inspect
i = inspect()
tasks = i.reserved()

      

However, when running this code, the task list is empty even if there are items in the queue (I checked that they are definitely in the queue using django-admin). The same is true for using the command line equivalent:

$ celeryctl inspect reserved

      

So my guess is that it isn't actually this command? If not, what is an acceptable way to get a list of tasks that have not yet started? Do I have to maintain my own list of task IDs in code in order to query them?

The reason I am asking is because I am trying to handle a situation where two tasks are queued that do a write operation on the same object in the database. If both tasks are running in parallel and task 1 takes longer than task 2, it will overwrite the result from task 2, but I want the result to be from the last task, that is, task 2. So my plan was to cancel any pending tasks that run the object every time a new task is added, which will write to the same object.

Thanks
Tom

+3


source to share


1 answer


You can see pending tasks using scheduled

instead reserved

.



$ celeryctl inspect scheduled

0


source







All Articles