From 2dded8155a3285b207b7036da3f59852eb90d296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 5 Apr 2017 16:26:01 +0200 Subject: [PATCH 1/2] general: add possibility to skip all cron jobs (#15470) This is useful for load balancing as jobs should only be run on one host. Original was amended with a condition on "--all-tenants" and help messages. Signed-off-by: Christophe Siraut --- hobo/multitenant/management/commands/tenant_command.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/hobo/multitenant/management/commands/tenant_command.py b/hobo/multitenant/management/commands/tenant_command.py index e80c9be..a1d33d5 100644 --- a/hobo/multitenant/management/commands/tenant_command.py +++ b/hobo/multitenant/management/commands/tenant_command.py @@ -3,7 +3,10 @@ # Email: carneiro.be@gmail.com # License: MIT license # Home-page: http://github.com/bcarneiro/django-tenant-schemas + import argparse + +from django.conf import settings from django.core.management.base import BaseCommand, CommandError from django.core.management import call_command, get_commands, load_command_class from django.db import connection @@ -15,7 +18,7 @@ class Command(InteractiveTenantOption, BaseCommand): help = "Wrapper around django commands for use with an individual tenant" args = '' - def run_from_argv(self, argv): + def run_from_argv(self, argv, **kwargs): """ Changes the option_list to use the options from the wrapped command. Adds schema parameter to specify which schema will be used when @@ -40,8 +43,18 @@ class Command(InteractiveTenantOption, BaseCommand): args_parser.add_argument("--all-tenants", help="apply command to all tenants", action='store_true') args_parser.add_argument("-d", "--domain", dest="domain_name", help="specify tenant domain name") + args_parser.add_argument( + '--force-job', dest='force_job', action='store_true', + help='Run command even if DISABLE_CRON_JOBS is set' ) args_namespace, args = args_parser.parse_known_args(argv) + if args_namespace.all_tenants and not args_namespace.force_job \ + and getattr(settings, 'DISABLE_CRON_JOBS', False): + if kwargs.get('verbosity') > 1: + print('Command %s is ignored because DISABLE_CRON_JOBS is set' + % app_name) + return + if args_namespace.all_tenants: for tenant in TenantMiddleware.get_tenants(): connection.set_tenant(tenant) -- 2.11.0