Registry / web-framework / django-cron

django-cron

JSON →
library0.6.0pypypi✓ verified 86d ago

A Django app for running cron jobs within your Django project. Current version 0.6.0, with support for Django 4.0. Release cadence is sporadic, last release in 2023.

pip install django-cron
INSTALL
IMPORT
SIG · DJANGO-CRON
D
django-cron
web-frameworkpythonv0.6.0
Install
3.5s avg
Import
542ms
Disk
66MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.570s · 66.5MB
glibc
py 3.103.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.
fix
Upgrade 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.
fix
Use 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.
fix
Define 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.
fix
Upgrade 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.
fix
Ensure 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)
Agent activity
22 hits · last 30 days
node
20
OpenAI (training)
1
Resources
django-cron — pip install django-cron · libregistry