问题
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