A Django app to define routines that should run periodically
Project description
Django Schedules
This app allows you to define routines that should run periodically (e.g. every day at 0:00, ...). They will be triggered by systemd-timers or cron.
Define Routines
- Add "schedules" to your
INSTALLED_APPS
setting. - Add a file called
schedules.py
to your django app. - Define functions in this file.
- Each function which is a timer job should be decorated by the
register
decorater:
Example:
import django_schedules
@django_schedules.register(mins=0, hour=0)
def run_at_midnight(**kwargs):
print('hello')
@django_schedules.register(mins=3, hour=18, day_of_month=2, month='5,11', lock=False, job_name='foobar')
def bar(**kwargs):
"""
Run on 2.5. and 2.11. at 18:03.
Don't use locking (allow to run this job more than once at the same time).
The job will be called 'foobar'.'
"""
print('hello')
Commands
Now you can use following management commands:
./manage.py schedules_list # list all available jobs
./manage.py schedules_update_systemd [-u user] [-p path] # generate systemd units (for user 'user' (default root))
./manage.py schedules_update_cron [-u user] [-o file] # generate crontab "code" (for user 'user' (default root)) (and write it to file file)
./manage.py schedules_run [<app_name>:]<job_name> [additional_args, ...] # run the job app_name:job_name
Installation
- Write your code (see above)
- Run
./manage.py schedules_list
to verify all jobs are registered as expected - Run
./manage.py schedules_update_systemd -u $DJANGO_USER [-p /etc/systemd/system/]
to generate systemd units - Or run
./manage.py schedules_update_cron -u $DJANGO_USER -o /etc/cron.d/$DJANGO_PROJECT_NAME
to let the jobs run by system cron
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-schedules-1.0.1.tar.gz
(12.1 kB
view hashes)