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] [--out-path 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 [--out-path /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.1.1.tar.gz
(10.3 kB
view hashes)
Built Distribution
Close
Hashes for django_schedules-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c448f79f06cf594790949423dea4b87a2d80f39f36df9645754da9e2fedcd951 |
|
MD5 | 65602ef728fe1c66433f08e0f4cd1007 |
|
BLAKE2b-256 | 3ba11be0e9d82a6373b2a4d8d584ac5ad752f0e20fdbc5b4f385f01731a73257 |