this is my celery task
def task_a(arg1, arg2, arg3, arg4)
and i call the task like following
arg1 is list and arg2,3,4 is integer
task_a.apply_async(arg1, arg2, arg3, arg4)
and i got an error message
File "/opt/envDjango/lib/python3.5/site-packages/celery/app/task.py", line 518, in apply_async
check_arguments(*(args or ()), **(kwargs or {}))
TypeError: functools.partial object argument after ** must be a mapping, not int
how can i solve the problem??
i tried to make a dictionary and change argument position, they are all failed...
Celery is a task queue/job queue based on asynchronous message passing. It can be used as a background task processor for your application in which you dump your tasks to execute in the background or at any given moment. It can be configured to execute your tasks synchronously or asynchronously.
It allows you to offload work from your Python app. Once you integrate Celery into your app, you can send time-intensive tasks to Celery's task queue. That way, your web app can continue to respond quickly to users while Celery completes expensive operations asynchronously in the background.
Bound tasks A task being bound means the first argument to the task will always be the task instance ( self ), just like Python bound methods: logger = get_task_logger(__name__) @app. task(bind=True) def add(self, x, y): logger.
Celery will stop retrying after 7 failed attempts and raise an exception.
delay
will work. This method is convenient as it looks like calling a regular function: see doc here
task_a.delay(*arg,**kwargs)
delay
is clearly convenient, but if you want to set additional execution options you have to use apply_async
.
task_a.apply_async(args=[arg1, arg2])
Note that the argument passed is a list.
To pass arguments to task with apply_async()
you need to wrap them in a list and then pass the list as first argument, I.e. apply_async([arg1, arg2, arg3])
. See the documentation for more details and examples.
Use delay()
as an alternative. The benefit is that it preserves more or less function’s parameters interface, i.e. it is not needed to wrap the args in a list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With