获取芹菜任务ID [英] Getting celery task id
本文介绍了获取芹菜任务ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做了类似的事情
@app.task
def some_task()
logger.info(app.current_task.request.id)
some_func()
def some_func()
logger.info(app.current_task.request.id)
所以我在some_task内收到普通ID,但在some_func内等于None.如何获得真实的任务ID?
So I receive normal id inside some_task, but it equals to None inside some_func. How can I get real task id?
推荐答案
您可以绑定任务并传递请求,而不必依赖全局.
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)
这篇关于获取芹菜任务ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文