Celery - Obtain the Task ID in task_success signal?

*爱你&永不变心* 提交于 2021-02-19 04:33:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!