Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions django_cron/management/commands/runcrons.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import traceback
from datetime import timedelta
import threading

from django.core.management.base import BaseCommand
from django.conf import settings
Expand Down Expand Up @@ -49,13 +50,29 @@ def handle(self, *args, **options):
self.stdout.write('Make sure these are valid cron class names: %s\n%s' % (cron_class_names, error))
return

threads = []
for cron_class in crons_to_run:
run_cron_with_cache_check(
cron_class,
force=options['force'],
silent=options['silent']
)
if getattr(settings,'DJANGO_CRON_MULTITHREADED',False):
## run all cron jobs in parallel as thread
th = threading.Thread(
target = run_cron_with_cache_check,
kwargs={
"cron_class":cron_class,
"force":options['force'],
"silent":options['silent']
}
)
th.start()
threads.append(th)
else:
run_cron_with_cache_check(
cron_class,
force=options['force'],
silent=options['silent']
)

for th in threads:
th.join()
clear_old_log_entries()
close_connection()

Expand Down
1 change: 1 addition & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ Configuration

**DJANGO_CRON_DELETE_LOGS_OLDER_THAN** - integer, number of days after which log entries will be clear (optional - if not set no entries will be deleted)

**DJANGO_CRON_MULTITHREADED** - run all cronjobs in parallel by using threads, default: ``False``

For more details, see :doc:`Sample Cron Configurations <sample_cron_configurations>` and :doc:`Locking backend <locking_backend>`