skip to navigation
skip to content

django-crontab 0.6.0

dead simple crontab powered job scheduling for django

.. image::
.. image::
.. image::
.. image::
.. image::


dead simple crontab powered job scheduling for django.

install via pip::

pip install django-crontab

add it to installed apps in django


now create a new method that should be executed by cron every 5 minutes, f.e. in `myproject/myapp/`::

def my_scheduled_job():

now add this to your

('*/5 * * * *', 'myproject.myapp.cron.my_scheduled_job')

you can also define positional and keyword arguments which let you call django management commands::

('*/5 * * * *', 'myproject.myapp.cron.other_scheduled_job', ['arg1', 'arg2'], {'verbose': 0}),
('0 4 * * *', '', ['clearsessions']),

finally run this command to add all defined jobs from `CRONJOBS` to crontab (of the user which you are running this command with)::

python crontab add

show current active jobs of this project::

python crontab show

removing all defined jobs is straight forward::

python crontab remove

there are a bunch of setting vars to customize behavior. each of this comes with default values that should properly fit. if not, feel free to overwrite.

- list of jobs, each defined as tuple:

- format 1:

1. required: cron timing (in usual format:
2. required: the python module path to the method
3. optional: a job specific suffix (f.e. to redirect out/err to a file, default: '')

- format 2:

1. required: cron timing (in usual format:
2. required: the python module path to the method
3. optional: list of positional arguments for the method (default: [])
4. optional: dict of keyword arguments for the method (default: {})
5. optional: a job specific suffix (f.e. to redirect out/err to a file, default: '')

- NOTE: Run "python crontab add" each time you change CRONJOBS in any way!
- default: []
- example::

('*/5 * * * *', 'myproject.myapp.cron.my_scheduled_job'),

# format 1
('0 0 1 * *', 'myproject.myapp.cron.my_scheduled_job', '> /tmp/last_scheduled_job.log'),

# format 2
('0 0 1 * *', 'myproject.myapp.cron.other_scheduled_job', ['myapp']),
('0 0 * * 0', '', ['dumpdata', 'auth'], {'indent': 4}, '> /home/john/backups/last_sunday_auth_backup.json'),

- prevent starting a job if an old instance of the same job is still running
- default: False
- since 0.5.0

- path to the crontab executable of your os
- default: '/usr/bin/crontab'

- the name of your django project, used to build path path to and to mark the jobs in contrab via comment for later removing
- default is read from DJANGO_SETTINGS_MODULE environment variable

- path to file (including the itself, i.e. '/home/john/web/')
- default is build using DJANGO_PROJECT_NAME

- dotted python path to the settings module to run the command with
- default is the common one from the environment variable and will not be overwritten
- since 0.6.0

- path to the python interpreter executable used to run the scheduled job
- default uses the interpreter executable used to `add` the jobs (via 'python crontab add')

- something you wanne do or declare before each job gets executed. A good point for environment variables.
- default: '' (empty string)
- example: 'STAGE=production'

- something you wanne do after each job was executed.
- default: '' (empty string)
- example: (do you know a good example?)

- used for marking the added contab-lines for removing, default value includes project name to distinguish multiple projects on the same host and user
- default: 'django-crontabs for ' + CRONTAB_DJANGO_PROJECT_NAME

arski cinghiale meric426 justdoit0823 chamaken

MIT-License, see LICENSE file.  
File Type Py Version Uploaded on Size
django-crontab-0.6.0.tar.gz (md5) Source 2014-12-07 5KB
django_crontab-0.6.0-py2.py3-none-any.whl (md5) Python Wheel 3.4 2014-12-07 9KB
  • Downloads (All Versions):
  • 135 downloads in the last day
  • 593 downloads in the last week
  • 3825 downloads in the last month