简体   繁体   中英

Where do you set the task_id of a celery task?

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

something along these lines...

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

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM