Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 PENDING state, but the system isn't processing anything... It's possible to retry this tasks giving celery the task_id?

like image 496
Antonio Beamud Avatar asked Feb 28 '11 10:02

Antonio Beamud


2 Answers

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

like image 199
Mauro Rocco Avatar answered Sep 18 '22 02:09

Mauro Rocco


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
like image 37
Ajay Gupta Avatar answered Sep 19 '22 02:09

Ajay Gupta