Running python crons in a Django 5 project
Project description
django-cron
A Django app for running scheduled tasks (cron jobs) within your Django project. This is a fork of Tivix/django-cron with full Django 5 compatibility.
Features
- Simple API: Define cron jobs with a clean, Pythonic interface
- Django 5 Compatible: Fully tested and working with Django 5.x
- Flexible Scheduling: Support for various schedule types (daily, hourly, custom intervals)
- Multiple Locking Backends: File, cache, and database-based locking to prevent concurrent runs
- Job Logging: Track job execution history and debug issues easily
- No System Cron Required: Jobs run within your Django process
Installation
Install from PyPI:
pip install django-cron-django5
Add django_cron to your INSTALLED_APPS:
INSTALLED_APPS = [
# ...
'django_cron',
]
Run migrations:
python manage.py migrate django_cron
Quick Start
Create a cron job by subclassing CronJobBase:
from django_cron import CronJobBase, Schedule
class MyCronJob(CronJobBase):
RUN_EVERY_MINS = 60 # Run every hour
schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
code = 'myapp.my_cron_job' # Unique code
def do(self):
# Your code here
pass
Register your cron job in settings:
CRON_CLASSES = [
'myapp.cron.MyCronJob',
]
Run cron jobs:
python manage.py runcrons
For continuous execution, use:
python manage.py cronloop
Requirements
- Python >= 3.9
- Django >= 4.2, < 6.0
Documentation
For detailed documentation, please visit the GitHub repository.
Contributing
We welcome contributions! Please see our GitHub repository for more information.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Credits
- Original project: Tivix/django-cron
- Maintained for Django 5 by Ticketping
Development Setup
Pre-requisites
- Python >= 3.9
We suggest using pyenv to easily manage python versions.
Configure local development setup
- Install and activate python:
pyenv install 3.11.13
pyenv virtualenv 3.11.13 djcron
pyenv local djcron
- Install project requirements:
pip install -r requirements-dev.txt
- Install pre-commit hooks (if
pre-commitis installed globally):
pre-commit install
Running Tests
python testmanage.py test django_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 Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_cron_django5-0.6.0-py2.py3-none-any.whl.
File metadata
- Download URL: django_cron_django5-0.6.0-py2.py3-none-any.whl
- Upload date:
- Size: 25.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42502855c9e03a29eaca43c0716f1ee358cfb31d8ebfbb769d6ac4fb4fa03cdd
|
|
| MD5 |
87498fe7ef87bf78491347f48a23be5a
|
|
| BLAKE2b-256 |
a938094983df4b52725f49b8008488a52cc23ece394ac8ebc7957a13afdfaf9c
|