1

I have made something like that

@app.task
def some_task()
    logger.info(app.current_task.request.id)
    some_func()

def some_func()
    logger.info(app.current_task.request.id)

So I receive normal id inside some_task, but it equals to None inside some_func. How can I get real task id?

RostSH
  • 13
  • 3

1 Answers1

2

You could bind the task and pass the request around rather than relying on a global.

@app.task(bind=True)
def some_task(self)
    logger.info(self.request.id)
    some_func(self.request)

def some_func(celery_request=None)
    # celery_request is optional assuming you're using it elsewhere.
    if celery_request:
        logger.info(celery_request.id)
schillingt
  • 13,493
  • 2
  • 32
  • 34