Projet

Général

Profil

0001-general-add-possibility-to-skip-all-cron-jobs-15470.patch

Christophe Siraut, 17 avril 2018 15:45

Télécharger (2,66 ko)

Voir les différences:

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 <csiraut@entrouvert.com>
 hobo/multitenant/management/commands/tenant_command.py | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
hobo/multitenant/management/commands/tenant_command.py
3 3
#   Email: carneiro.be@gmail.com
4 4
#   License: MIT license
5 5
#   Home-page: http://github.com/bcarneiro/django-tenant-schemas
6

  
6 7
import argparse
8

  
9
from django.conf import settings
7 10
from django.core.management.base import BaseCommand, CommandError
8 11
from django.core.management import call_command, get_commands, load_command_class
9 12
from django.db import connection
......
15 18
    help = "Wrapper around django commands for use with an individual tenant"
16 19
    args = '<other_command>'
17 20

  
18
    def run_from_argv(self, argv):
21
    def run_from_argv(self, argv, **kwargs):
19 22
        """
20 23
        Changes the option_list to use the options from the wrapped command.
21 24
        Adds schema parameter to specify which schema will be used when
......
40 43
        args_parser.add_argument("--all-tenants", help="apply command to all tenants",
41 44
                                 action='store_true')
42 45
        args_parser.add_argument("-d", "--domain", dest="domain_name", help="specify tenant domain name")
46
        args_parser.add_argument(
47
            '--force-job', dest='force_job', action='store_true',
48
            help='Run command even if DISABLE_CRON_JOBS is set' )
43 49
        args_namespace, args = args_parser.parse_known_args(argv)
44 50

  
51
        if args_namespace.all_tenants and not args_namespace.force_job \
52
           and getattr(settings, 'DISABLE_CRON_JOBS', False):
53
            if kwargs.get('verbosity') > 1:
54
                print('Command %s is ignored because DISABLE_CRON_JOBS is set'
55
                      % app_name)
56
            return
57

  
45 58
        if args_namespace.all_tenants:
46 59
            for tenant in TenantMiddleware.get_tenants():
47 60
                connection.set_tenant(tenant)
48
-