2

we are running Django v1.10 with celery v4.0.2, rabbitMQ v3.5.7 and flower v0.9.1 and are pretty new with celery, rabbitMQ and flower.

There is a function x() which was set to retry after 7 days in case of failure. We have 1000's of instances of x re-queued on production. We have fixed the issue and would like to retry the instances asap.

Is there a way to force the retry before it's scheduled time?

2 Answers2

0

If you can get a list of the tasks, it's a matter of calling task.retry(exc=exc) on each one. See docs.

Try celery.task.control.inspect().reserved() and see if you can filter the tasks that way. Example here.

You get a task object from its id with this, per this answer.

result = MyTask.AsyncResult(task_id)
result.get()
Jared Nielsen
  • 3,669
  • 9
  • 25
  • 36
  • 1
    I tried that, but inspect.scheduled() doesn't return task object but dictionary representation of it and thus i cant call task.retry on it. I have been trying to find how to get task object from task id but haven't been able to find it. It would be great if you can share an alternative/share how to get task object from its id. – Prakhar Gupta Jul 18 '17 at 06:48
  • @PrakharGupta Try `MyTask.AsyncResult()` – Jared Nielsen Jul 18 '17 at 13:57
0

So after trying a lot of things, I had to solve it by getting the list of scheduled tasks and their arguments and calling the functions in a for loop with the arguments.

There is apparently no way to retry a task manually by design. You have to create another task with the same parameters. This is what I finally did:

i = inspect()
scheduled = i.scheduled()
for key in scheduled:
    for element in scheduled[key]:
        reqDict = element['request']
        if reqDict['type']=='module.function':
            module.function.delay(converted_arguments)
            revoke(reqDict['id'], terminate=True)