简体   繁体   中英

get the task_id in celery

How can I get the task id from the tasks.py in celery

from __future__ import absolute_import
from pig_engine.celery import app
import time

@app.task
def run(code):
    result = task_id /// How to get the task id
    return result

I know we can get the task id from run.delay().id , but how can get same id in tasks it self

Get task's info from request object

@app.task(bind=True)
def run(self,code):
    result = self.request.id #task id
    return result

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