在Celery任务中获取task_id [英] Getting task_id inside a Celery task
本文介绍了在Celery任务中获取task_id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能是一个愚蠢的问题,但是它使我陷入了来自Ruby背景的麻烦。
This is probably a stupid question but its got me stumped coming from a Ruby background.
当我尝试打印它时,我有一个看起来像这样的对象。
I have an object that looks like this when I try to print it.
print celery.AsyncResult.task_id
>>><property object at 0x10c383838>
我期望在这里打印task_id属性的实际值。如何获得实际值?
I was expecting the actual value of the task_id property to be printed here. How do I get to the actual value?
更新1
@celery.task
def scan(host):
print celery.AsyncResult.task_id
cmd = 'ps -ef'
cm = shlex.split(cmd)
scan = subprocess.check_output(cm)
return scan
推荐答案
短篇小说,在函数 scan
中使用 scan.request.id
。
Short story, within function scan
, use scan.request.id
.
请参见 http://docs.celeryproject.org/en/latest/userguide/tasks.html?highlight=request#任务请求信息
这篇关于在Celery任务中获取task_id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文