multitenant: use TENANT_DISABLE_CRON_JOBS to disable cron for a specific tenant (#57527)

This commit is contained in:
Emmanuel Cazenave 2021-10-05 11:37:50 +02:00
parent add04ecadb
commit 5b229eb31d
2 changed files with 18 additions and 3 deletions

View File

@ -133,9 +133,9 @@ class Command(InteractiveTenantOption, BaseCommand):
errors = []
for tenant in TenantMiddleware.get_tenants():
connection.set_tenant(tenant)
if getattr(settings, 'DISABLE_CRON_JOBS', False):
if getattr(settings, 'TENANT_DISABLE_CRON_JOBS', False):
if args_verbosity.verbosity > 1 or args_namespace.force_job:
msg = 'Command %s is ignored on tenant %s because DISABLE_CRON_JOBS is set' % (
msg = 'Command %s is ignored on tenant %s because TENANT_DISABLE_CRON_JOBS is set' % (
app_name,
tenant.domain_url,
)

View File

@ -50,6 +50,7 @@ def test_all_tenants(handle, tenants):
def test_all_tenants_disable_cron(handle, tenants, settings):
from django.core.management import execute_from_command_line
settings.clear_tenants_settings()
settings.DISABLE_CRON_JOBS = True
handle.side_effect = RecordTenant()
execute_from_command_line(['manage.py', 'tenant_command', 'clearsessions', '--all-tenants'])
@ -65,7 +66,7 @@ def test_all_tenants_disable_cron_for_specific_tenant(handle, tenants, settings)
disabled_tenant = tenants[0]
with open(os.path.join(disabled_tenant.get_directory(), 'settings.json'), 'w') as fd:
json.dump(
{'DISABLE_CRON_JOBS': True},
{'TENANT_DISABLE_CRON_JOBS': True},
fd,
)
handle.side_effect = RecordTenant()
@ -74,6 +75,20 @@ def test_all_tenants_disable_cron_for_specific_tenant(handle, tenants, settings)
assert len(handle.side_effect.tenants) == 1
@mock.patch('django.contrib.sessions.management.commands.clearsessions.Command.handle')
def test_all_tenants_global_disable_cron_with_force_job(handle, tenants, settings):
from django.core.management import execute_from_command_line
settings.clear_tenants_settings()
settings.DISABLE_CRON_JOBS = True
handle.side_effect = RecordTenant()
execute_from_command_line(
['manage.py', 'tenant_command', 'clearsessions', '--all-tenants', '--force-job']
)
assert handle.call_count == 2
assert len(handle.side_effect.tenants) == 2
@mock.patch('django.contrib.sessions.management.commands.clearsessions.Command.handle')
def test_one_tenant(handle, tenants, tenant_in_call=None):
from django.core.management import execute_from_command_line