Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Celery Beat - How to pass arguments using the DatabaseScheduler

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,

like image 409
André Avatar asked Mar 28 '13 19:03

André


People also ask

How do you pass arguments in celery task?

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.

How do you use celery beat in Django?

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.

How do you run a celery beat schedule?

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 .

What does celery beat do?

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.


1 Answers

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"}
like image 136
kanishk Avatar answered Sep 19 '22 05:09

kanishk