How to get the failed tasks in Celery?

前端 未结 2 464
执笔经年
执笔经年 2021-01-06 16:05

I am using celery to process some tasks. I can see how many are active or scheduled etc, but I am not able to find any way to see the tasks that have failed. Flower does sho

2条回答
  •  隐瞒了意图╮
    2021-01-06 16:49

    task id has state and status properties. So you can get the status of tasks by id.

    my_task_id = my_task.delay(foo)
    my_task_id.state
    my_task_id.status
    

    gives the status whether it is PENDING, STARTED, RETRY, FAILURE or SUCCESS.

    afaik, celery show only active, scheduled, reserved, revoked but id doesn't show failed tasks.

    Since you have all task id's, you can just loop over their status.

    for task_id in task_id_list:
        if task_id.state == 'FAILURE'
            print(task_id)
    

提交回复
热议问题