Skip to content

Commit

Permalink
[DOCS]: Django crontab integration (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvandernoort authored Jan 29, 2024
1 parent 276191c commit 670236a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions docs/integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,33 @@ Example of cron job with `django-cron`_ with file system storage: ::
management.call_command('dbbackup')

.. _`django-cron`: https://github.com/Tivix/django-cron

Django-crontab
--------------

Example of cron job with `django-crontab`_ with file system storage:

In `settings.py`: ::

CRONTAB_COMMAND_SUFFIX = '2>&1'
CRONJOBS = [
('0 5 * * *', 'core.backup.backup_job', '>> ' + os.path.join(CORE_DIR, 'backup/backup.log'))
]

In `backup.py`: ::

from datetime import datetime
from django.core import management
def backup_job():
print("[{}] Backing up database and media files...".format(datetime.now()))
management.call_command('dbbackup', '--clean')
management.call_command('mediabackup', '--clean')
print("[{}] Backup done!".format(datetime.now()))


To add the cron job: ::

python manage.py crontab add

.. _`django-crontab`: https://github.com/kraiz/django-crontab

0 comments on commit 670236a

Please sign in to comment.