disable cron command if settings.DISABLE_CRON_JOBS is set (#26863)
This commit is contained in:
parent
dfe2cba424
commit
5d1e59d7b6
|
@ -10,8 +10,10 @@ import zipfile
|
|||
import mock
|
||||
import pytest
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management import call_command
|
||||
from django.core.management.base import CommandError
|
||||
from django.test import override_settings
|
||||
from quixote import cleanup
|
||||
from wcs.qommon.http_request import HTTPRequest
|
||||
|
||||
|
@ -205,3 +207,9 @@ def test_cron_command():
|
|||
with mock.patch('wcs.qommon.management.commands.cron.cron_worker') as cron_worker:
|
||||
call_command('cron')
|
||||
assert cron_worker.call_count == 1
|
||||
|
||||
# disable cron system
|
||||
with override_settings(DISABLE_CRON_JOBS=True):
|
||||
with mock.patch('wcs.qommon.management.commands.cron.cron_worker') as cron_worker:
|
||||
call_command('cron')
|
||||
assert cron_worker.call_count == 0
|
||||
|
|
|
@ -18,6 +18,7 @@ import tempfile
|
|||
import time
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from qommon.publisher import get_publisher_class
|
||||
|
||||
|
@ -31,8 +32,14 @@ class Command(BaseCommand):
|
|||
|
||||
def add_arguments(self, parser):
|
||||
parser.set_defaults(verbosity=0)
|
||||
parser.add_argument('--force-job', dest='force_job', action='store_true',
|
||||
help='Run even if DISABLE_CRON_JOBS is set in settings')
|
||||
|
||||
def handle(self, verbosity, **kwargs):
|
||||
def handle(self, verbosity, **options):
|
||||
if getattr(settings, 'DISABLE_CRON_JOBS', False) and not options['force_job']:
|
||||
if verbosity > 1:
|
||||
print('Command is ignored because DISABLE_CRON_JOBS is set in settings')
|
||||
return
|
||||
lockfile = os.path.join(tempfile.gettempdir(), 'wcs-cron-in-progress.lock')
|
||||
try:
|
||||
with locket.lock_file(lockfile, timeout=0):
|
||||
|
|
|
@ -159,6 +159,11 @@ REQUESTS_PROXIES = None
|
|||
# we use 28s by default: timeout just before web server, which is usually 30s
|
||||
REQUESTS_TIMEOUT = 28
|
||||
|
||||
# For high availability installations with multiple instances of w.c.s.
|
||||
# components, one should disable cron jobs execution on secondary servers;
|
||||
# set the following variable True disables "cron" management command
|
||||
DISABLE_CRON_JOBS = False
|
||||
|
||||
local_settings_file = os.environ.get('WCS_SETTINGS_FILE',
|
||||
os.path.join(os.path.dirname(__file__), 'local_settings.py'))
|
||||
if os.path.exists(local_settings_file):
|
||||
|
|
Loading…
Reference in New Issue