Antonio Beamud
Antonio Beamud

Reputation: 2341

Retry a task in celery by task id

I've launched a lot of tasks, but some of then hasn't finished (763 tasks), are in a PENDING state, but the system isn't processing anything... It's possible to retry this tasks giving celery the task_id?

Upvotes: 8

Views: 8214

Answers (2)

Ajay Gupta
Ajay Gupta

Reputation: 1845

This works now after setting celery.conf.update(result_extended=True) which persists the arguments passed to the task:

def retry_task(task_id):    
    meta=celery.backend.get_task_meta(task_id)
    task = celery.tasks[meta['name']]
    task.apply_async(args=meta['args'], kwargs=meta['kwargs']) #specify any other parameters you might be passing

Upvotes: 5

Mauro Rocco
Mauro Rocco

Reputation: 5128

You can't. You can retry a task only from inside itself, you can't do it from outside.

The best thing to do in this case is to run again the task type with the same args, in this way you will do the same JOB but with a new PID that identify your process/task.

Remember also that the celery PENDING state not means only that the task is waiting for execution, but maybe that is unknown.

http://celeryq.org/docs/userguide/tasks.html#pending

I hope this could help

Upvotes: 14

Related Questions