Package: dj-crontab
aboutdead simple crontab powered job scheduling for django (1.8-3.1).setupinstall via pip:pipinstalldj-crontabadd it to installed apps in django settings.py:INSTALLED_APPS=('django_crontab',...)now create a new method that should be executed by cron every 5 minutes, f.e. inmyapp/cron.py:defmy_scheduled_job():passnow add this to your settings.py:CRONJOBS=[('*/5 * * * *','myapp.cron.my_scheduled_job')]you can also define positional and keyword arguments which let you call django management commands:CRONJOBS=[('*/5 * * * *','myapp.cron.other_scheduled_job',['arg1','arg2'],{'verbose':0}),('0   4 * * *','django.core.management.call_command',['clearsessions']),]finally, run this command to add all defined jobs fromCRONJOBSto crontab (of the user which you are running this command with):pythonmanage.pycrontabaddshow current active jobs of this project:pythonmanage.pycrontabshowremoving all defined jobs is straightforward:pythonmanage.pycrontabremoveconfigthere are a bunch of setting vars to customize behavior. each of them comes with default values that should properly fit. if not, feel free to overwrite.CRONJOBSlist of jobs, each defined as a tuple:format 1:required: cron timing in usual format (seeWikipediaandcrontab.gurufor more examples)required: the python module path to the methodoptional: a job-specific suffix (f.e. to redirect out/err to a file, default: ‘’)format 2:required: cron timingrequired: the python module path to the methodoptional: list of positional arguments for the method (default: [])optional: dict of keyword arguments for the method (default: {})optional: a job specific suffix (f.e. to redirect out/err to a file, default: ‘’)NOTE: Run “python manage.py crontab add” each time you change CRONJOBS in any way!default: []example:CRONJOBS=[('*/5 * * * *','myapp.cron.my_scheduled_job'),# format 1('0   0 1 * *','myapp.cron.my_scheduled_job','>> /tmp/scheduled_job.log'),# format 2('0   0 1 * *','myapp.cron.other_scheduled_job',['myapp']),('0   0 * * 0','django.core.management.call_command',['dumpdata','auth'],{'indent':4},'> /home/john/backups/last_sunday_auth_backup.json'),]CRONTAB_LOCK_JOBSprevent starting a job if an old instance of the same job is still runningdefault: Falsesince 0.5.0CRONTAB_EXECUTABLEpath to the crontab executable of your osdefault: ‘/usr/bin/crontab’CRONTAB_DJANGO_PROJECT_NAMEthe name of your django project, used to build path path to manage.py and to mark the jobs in crontab via comment for later removingdefault is read from DJANGO_SETTINGS_MODULE environment variableCRONTAB_DJANGO_MANAGE_PATHpath to manage.py file (including the manage.py itself, i.e. ‘/home/john/web/manage.py’)default is build using DJANGO_PROJECT_NAMECRONTAB_DJANGO_SETTINGS_MODULEdotted python path to the settings module to run the command withdefault is the common one from the environment variable and will not be overwrittensince 0.6.0CRONTAB_PYTHON_EXECUTABLEpath to the python interpreter executable used to run the scheduled jobdefault uses the interpreter executable used toaddthe jobs (via ‘python manage.py crontab add’)CRONTAB_COMMAND_PREFIXsomething you want to do or declare, before each job gets executed. A good place for environment variables.default: ‘’ (empty string)example: ‘STAGE=production’CRONTAB_COMMAND_SUFFIXsomething you want to do after each job was executed.default: ‘’ (empty string)example: ‘2>&1’CRONTAB_COMMENTused for marking the added contab-lines for removing, default value includes project name to distinguish multiple projects on the same host and userdefault: ‘django-crontabs for ‘ + CRONTAB_DJANGO_PROJECT_NAMEcontributorsarski cinghiale meric426 justdoit0823 chamakenfaqI’m using this old django version (<1.8) and can’t install this package. What should i do?- Yeah, update django of course (!) or - as you seem to be familiar with old, unsupported versions, install the old version of this package too (it support django 1.3-1.7):pip install django-crontab==0.6.0Will it work with windows?- No.Will it work within a docker?- Not immediately, you need to start the cron service.Problems with `pyenv`?- You maybe need to setup the PATH variable within crontab. Have a look at#60I’m getting “bad command”/”errors in cronfile” while installing via “crontab add”. What’s wrong?- Maybe it’s your cron time format, it can have 5 or 6 fields. Check that your system supports 6 or just define 5 inCRONJOBS. (see #23)Why does the LOGGING not work when started via cronjob?- That’s maybe something about the current working dir. Please set your FileHandler’s file path absolute and try again. (see#31)licenseMIT-License, see LICENSE file.