Is it possible to configure a sophisticated schedule with celery beat? For example, something like this:
On Monday-Friday, do job A with parameters (x1, y1), then do job B On Saturday, Sunday, do job A with parameters (x2, y2), don't do job B
I know I can implement a high frequency "tick" task that will check for this schedule, but I don't want to reinvent the wheel if something for this already exists.
Here are some key points: DJANGO_SETTINGS_MODULE must be set in the environment before starting a Celery process. Its presence in the environment triggers internal magic in Celery to run the Django setup at the right time. The Celery "application" must be created and configured during startup of both Django and Celery.
The "shared_task" decorator allows creation of Celery tasks for reusable apps as it doesn't need the instance of the Celery app. It is also easier way to define a task as you don't need to import the Celery app instance.
Celery is an asynchronous task queue/job queue based on distributed message passing. It is focused on real-time operations but supports scheduling as well. The execution units, called tasks, are executed concurrently on one or more worker servers using multiprocessing, Eventlet, or gevent.
Sure, use a crontab schedule for your tasks.
from celery.schedules import crontab
CELERYBEAT_SCHEDULE = {
# Executes every weekday morning at 7:30 A.M
'weekdays': {
'task': 'tasks.A',
'schedule': crontab(hour=7, minute=30, day_of_week='1-5'),
'args': (x1, y1),
},
# Executes saturday at 4:00 A.M
'saturday': {
'task': 'tasks.B',
'schedule': crontab(hour=4, minute=0, day_of_week='sat'),
'args': (x1, y1),
},
# Executes sunday morning at 2:15 A.M
'sunday': {
'task': 'tasks.A',
'schedule': crontab(hour=2, minute=15, day_of_week='sun'),
'args': (x2, y2),
},
}
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