Projet

Général

Profil

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

Christophe Siraut, 17 avril 2018 16:41

Télécharger (3,33 ko)

Voir les différences:

Subject: [PATCH] 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>
 debian/debian_config_common.py                         |  6 ++++++
 hobo/multitenant/management/commands/tenant_command.py | 15 ++++++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
debian/debian_config_common.py
24 24

  
25 25
EMAIL_SUBJECT_PREFIX = '[%s] ' % PROJECT_NAME
26 26

  
27
# For high availability installations with multiple instances of Publik
28
# components, one should disable cron jobs execution on secondary servers;
29
# set the following variable True disables all tenant_commands launched with
30
# option "--all-tenants".
31
DISABLE_CRON_JOBS = False
32

  
27 33
LOGGING = {
28 34
    'version': 1,
29 35
    'disable_existing_loggers': True,
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 and
52
                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
-