Skip to content

Instantly share code, notes, and snippets.

@jsmolina
Created May 9, 2018 16:58
Show Gist options
  • Save jsmolina/2218cc006ce3a9e6faa9b081abde3086 to your computer and use it in GitHub Desktop.
Save jsmolina/2218cc006ce3a9e6faa9b081abde3086 to your computer and use it in GitHub Desktop.
Celery cron (beat) service learned things
Executing a new task periodically in celery like in java quartz, is as simple as:
0) Define your tasks in a dictionary (function check_users in background_tasks module will execute every half an hour):
beat_schedule = {
'check_users': {
task: 'backoffice.blueprints.users.background_tasks.check_users'
schedule: 1800.0
}
}
1) Launch scheduler: this scheduler WON'T execute the tasks, it will just schedule them on time.
celery -A app.celery beat -s /var/tmp/celerybeat-schedule -l DEBUG --pidfile /var/tmp/celerybeat-pid
2) Launch celery workers: this workers will take all celery tasks and run them, including the ones launched from scheduler.
celery -A app.celery worker -n worker.main@%h --max-tasks-per-child 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment