简体   繁体   中英

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM