问题
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:
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)
来源:https://stackoverflow.com/questions/46541590/celery-obtain-the-task-id-in-task-success-signal