Projet

Général

Profil

0001-don-t-start-a-new-cron-if-locked-18519.patch

Thomas Noël, 08 septembre 2017 00:10

Télécharger (2,08 ko)

Voir les différences:

Subject: [PATCH] don't start a new cron if locked (#18519)

 wcs/qommon/management/commands/cron.py | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
wcs/qommon/management/commands/cron.py
21 21
from django.core.management.base import BaseCommand
22 22
from qommon.publisher import get_publisher_class
23 23

  
24
from qommon import get_logger
24 25
from qommon.vendor import locket
25 26
from qommon.cron import cron_worker
26 27

  
......
29 30
    help = 'Execute cronjobs'
30 31

  
31 32
    def handle(self, verbosity, **options):
32
        with locket.lock_file(os.path.join(tempfile.gettempdir(), 'wcs-cron')):
33
            now = time.localtime()
34
            publisher_class = get_publisher_class()
35
            publisher_class.register_cron = True
36
            publisher = publisher_class.create_publisher()
37
            app_dir = publisher.app_dir
38
            for hostname in publisher.get_tenants():
39
                publisher.app_dir = os.path.join(app_dir, hostname)
40
                cron_worker(publisher, now)
33
        lockfile = os.path.join(tempfile.gettempdir(), 'wcs-cron-in-progress.lock')
34
        try:
35
            with locket.lock_file(lockfile, timeout=0):
36
                now = time.localtime()
37
                publisher_class = get_publisher_class()
38
                publisher_class.register_cron = True
39
                publisher = publisher_class.create_publisher()
40
                app_dir = publisher.app_dir
41
                for hostname in publisher.get_tenants():
42
                    publisher.app_dir = os.path.join(app_dir, hostname)
43
                    cron_worker(publisher, now)
44
        except locket.LockError:
45
            get_logger().warn('can not start cron job - locked by %s' % lockfile)
41
-