Pass parameter request to a celery task in Django

最后都变了- 提交于 2019-12-11 14:47:31

问题


I have a simple issue, we have as follows:

@task()
def upload_image(request):
     var = request.POST

     # ... do something

And we call it in another method the delay for this method like this:

job = upload_image.delay(request)

This not works obviously, after I read, you can pass messages to a celery task like a simple arg, args or kwargs** but what I just want is to pass a simple object, not a string or list of strings, is there anyway to do this in celery?

Regards!


回答1:


As you can read from the docs your example should work.

from celery import task

@task()
def add(x, y):
    return x + y

add.delay(2, 2)



回答2:


This should work as long as you're using standard pickle serializer.




回答3:


This does not work with the standard pickler. See more here (basically a duplicate): passing django request object to celery task



来源:https://stackoverflow.com/questions/18549164/pass-parameter-request-to-a-celery-task-in-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!