如何获取下一个celery任务的标识,或者如何从任务本身(Flask)中获取任务标识,或者如何为任务设置自定义标识?

2024-09-30 06:28:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我的烧瓶软件里有一些芹菜:

# Initialize Celery
celery = Celery("DockerApp", broker=config['CELERY_BROKER_URL'])
celery.conf.update(config)

我的任务是:

^{pr2}$

我需要任务本身内的任务id,或者我需要将该id设置为我自己。 有人能帮忙吗?在

当我调用任务时:

result = some_task.delay(data)
print result.id #this is correct

这给了我正确的结果。在


Tags: idconfigurl软件烧瓶confbrokerresult
2条回答

我用的是:

from celery import current_task #in task definition
print current_task.request.id

不管怎样,谢谢你。在

您还可以通过以下方式访问任务内部的任务请求:

@celery.task(bind=True)
def some_task(self, data):
    print self.request.id

相关问题 更多 >

    热门问题