您在哪里设置芹菜任务的task_id? [英] Where do you set the task_id of a celery task?

查看:120
本文介绍了您在哪里设置芹菜任务的task_id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到使用我自己的task_id设置task_id的任何示例

I am having trouble finding any example of setting a task_id with my own task_id

类似这些东西...

def testview1(request):
    for i in xrange(0,1000):
        result = add.delay( i, 4,task_id = i)
        print result.info
        #value = result.wait()
    return HttpResponse("Done") 


@task()
def add(task_id, x, y):
    print add.task_id
    print str(x+y)
    return x + y


推荐答案

延迟不支持选项,这是apply_async的快捷方式:

delay doesn't support options, it's a shortcut to apply_async:

add.apply_async(args, kwargs, task_id=i)

add.apply_async((1, 4), task_id=i)

当前任务的ID在 task.request.id 不是 task.id ,就像上面一样。

Also the id of the current task is in task.request.id not task.id like you have above.

这篇关于您在哪里设置芹菜任务的task_id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆