How To Configure Celerybeat_schedule In Django Settings?
I can get this to run as a standalone application, but I am having trouble getting it to work in Django. Here is the stand alone code: from celery import Celery from celery.schedul
Solution 1:
Why don't you try like the following and let me know if it worked out for you or not. It does work for me.
In settings.py
CELERYBEAT_SCHEDULE = {
'my_scheduled_job': {
'task': 'run_scheduled_jobs', # the same goes in the task name'schedule': crontab(),
},
}
And in tasks.py..
from celery.task import task # notice the import of task and not shared task. @task(name='run_scheduled_jobs') # task name found! celery will do its jobdefrun_scheduled_jobs():
# do whatever stuff you doreturnTrue
But if you are looking for shared_task then..
@shared_task(name='my_shared_task') # name helps celery identify the functions it has to rundefmy_shared_task():
# do what you want here..returnTrue
I use shared task for async jobs.. So I need to call it from a function like the following..
in views.py / or anywhere.py in your project app
def some_function():
my_shared_task.apply_async(countdown= in_seconds)
return True
and just in case if you have forgotten then remember to include your app in which you are trying to run to the tasks..
INSTALLED_APPS = [...
'my_app'...
] # include app
I'm sure this approach works fine.. Thanks
Post a Comment for "How To Configure Celerybeat_schedule In Django Settings?"