madan ram
madan ram

Reputation: 1270

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

Upvotes: 2

Views: 5002

Answers (1)

xecgr
xecgr

Reputation: 5193

Get task's info from request object

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

Upvotes: 8

Related Questions