I'm using the "DatabaseScheduler" with the Django Celery Beat, but I can't pass arguments to the function.
The settings:
# Django celery
import djcelery
djcelery.setup_loader()
BROKER_URL = 'django://'
CELERYBEAT_SCHEDULER = "djcelery.schedulers.DatabaseScheduler"
The task:
@task()
def some_task(days):
# Some code
...
How can I pass the argument "days" using the Django admin? I've created a new "Periodic Task" calling the "some_task". I've tried to pass the argument days with:
Arguments: [7]
and also tested:
Keyword arguments: {"days": 7}
Someone can give me a clue on how to pass arguments using the Django admin?
Best Regards,
Answers 2 : of how can i pass argument to celery task 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.
To use the Celery Beat, we need to configure the Redis server in the Django projects settings.py file. As we have installed the Redis server on the local machine, we will point the URL to localhost. The CELERY_TIMEZONE variable must be correctly set to run the tasks at the intended times.
This command has used for start the celery beat. Firstly add the django_celery_beat module in installed apps in settings file. And then apply the django migrate command, this will create the tables in admin pannel. After completing all the process like in celery file and create task in tasks.py .
Introduction. celery beat is a scheduler; It kicks off tasks at regular intervals, that are then executed by available worker nodes in the cluster. By default the entries are taken from the beat_schedule setting, but custom stores can also be used, like storing the entries in a SQL database.
The arguments and keyword arguments must use double quotes.
So if you are specifying arguments, it should be like:
["aa", "11"]
If you are specifying keyword arguments, it should be like this:
{"abc": "a", "xyz": "1"}
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