Celery - Obtain the Task ID in task_success signal?

Viewed 1052

I have an application that implements the task_success signal like this:

@signals.task_success.connect
def task_success_handler(sender=None,result=None,**kwargs):
    print("**************************C100")
    pprint.pprint(sender.name)
    print("**************************C100")

I can obtain the task name. Is there any way to obtain the task_id?

1 Answers

As mentioned in documentation, sender is the task object executed. Task object has request attribute which has all the information related to the task.

To get task_id, you can do sender.request.id access.

@signals.task_success.connect
def task_success_handler(sender=None,result=None,**kwargs):
    print(sender.request.id)
Related