Install & Compatibility
Where this runs
tested against v0.6.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.570s · 66.5MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 3.5s · import 0.514s · 67MB
66MB installed
● package 66MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
CronJobBase
✓ from django_cron import CronJobBase
✗ from django_cron.models import CronJobBase
CronJobBase is a class in django_cron module, not from models
Schedule
✓ from django_cron import Schedule
get_current_cron_jobs
✓ from django_cron import get_current_cron_jobs
✗ from django_cron.management.commands import get_current_cron_jobs
Function is in the main django_cron module, not under management commands
Define a cron job class, then run 'python manage.py runcrons' to execute jobs that are due.
from django_cron import CronJobBase, Schedule
class MyCronJob(CronJobBase):
RUN_EVERY_MINS = 120 # every 2 hours
schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
code = 'my_app.my_cron_job' # a unique code
def do(self):
# your logic here
print("Cron job executed")
Debug
Known issues
breakingDjango 4.0 support requires django-cron >= 0.6.0. Older versions will fail on Django 4.0 due to removed utc/unaware datetime handling.fixUpgrade to django-cron >= 0.6.0.
affects: django-cron < 0.6.0 with Django >= 4.0
gotchaRUN_EVERY_MINS must be an integer. Setting it to a float like 0.5 will raise an error because the lock file mechanism expects an integer.fixUse integer minutes, e.g., RUN_EVERY_MINS = 1 instead of 0.5.
affects: all
deprecatedThe 'RUN_EVERY_MINS' attribute is deprecated in favor of specifying the schedule via a 'Schedule' object with 'run_every_mins' or 'run_at_times'. In future versions, using just RUN_EVERY_MINS may stop working.fixDefine a 'schedule' attribute using django_cron.Schedule instead of relying on the old RUN_EVERY_MINS class attribute.
affects: >= 0.6.0
Errors
Common errors & fixes
'NoneType' object has no attribute 'utcoffset'
This error occurs when using Django 2.0+ with django-cron < 0.5.1 due to changes in datetime handling.
fixUpgrade to django-cron >= 0.5.1.
django_cron.models.CronJobBase.MultipleObjectsReturned
Having duplicate cron jobs with the same 'code' in the database. The runcrons command expects uniqueness.
fixEnsure each CronJob class has a unique 'code' attribute, and delete duplicate entries from the cron_jobs database table.
Upgrade
Version history
0.6.0latest on PyPI · released May 11, 2022
Audit
Dependencies
djangorequiredRequires Django (minimum 1.8, supports up to 4.x)