Projet

Général

Profil

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

Christophe Siraut, 19 avril 2018 09:56

Télécharger (3,39 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 ++++++
 .../management/commands/tenant_command.py           | 21 +++++++++++++++++++++
 2 files changed, 27 insertions(+)
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
1
# -*- coding: utf-8 -*-
1 2
# this file derive from django-tenant-schemas
2 3
#   Author: Bernardo Pires Carneiro
3 4
#   Email: carneiro.be@gmail.com
4 5
#   License: MIT license
5 6
#   Home-page: http://github.com/bcarneiro/django-tenant-schemas
7

  
6 8
import argparse
9

  
10
from django.conf import settings
7 11
from django.core.management.base import BaseCommand, CommandError
8 12
from django.core.management import call_command, get_commands, load_command_class
9 13
from django.db import connection
......
40 44
        args_parser.add_argument("--all-tenants", help="apply command to all tenants",
41 45
                                 action='store_true')
42 46
        args_parser.add_argument("-d", "--domain", dest="domain_name", help="specify tenant domain name")
47
        args_parser.add_argument(
48
            '--force-job', dest='force_job', action='store_true',
49
            help='Run command even if DISABLE_CRON_JOBS is set')
43 50
        args_namespace, args = args_parser.parse_known_args(argv)
44 51

  
52
        # Continue weirdness: parse verbosity option and also leave it in args
53
        # for subcommand consumption
54
        verbosity_parser = argparse.ArgumentParser()
55
        verbosity_parser.add_argument('-v', '--verbosity', action='store',
56
                                      dest='verbosity', default=1, type=int)
57
        args_verbosity, _ = verbosity_parser.parse_known_args(args)
58

  
59
        if (args_namespace.all_tenants and not args_namespace.force_job and
60
                getattr(settings, 'DISABLE_CRON_JOBS', False)):
61
            if args_verbosity.verbosity > 1:
62
                print('Command %s is ignored because DISABLE_CRON_JOBS is set'
63
                      % app_name)
64
            return
65

  
45 66
        if args_namespace.all_tenants:
46 67
            for tenant in TenantMiddleware.get_tenants():
47 68
                connection.set_tenant(tenant)
48
-