Projet

Général

Profil

0001-misc-run-hourly-jobs-at-a-fixed-minute-25402.patch

Frédéric Péters, 21 juillet 2018 09:48

Télécharger (2,79 ko)

Voir les différences:

Subject: [PATCH] misc: run hourly jobs at a fixed minute (#25402)

 wcs/publisher.py        | 3 +--
 wcs/qommon/cron.py      | 8 +++++++-
 wcs/qommon/publisher.py | 4 ++--
 3 files changed, 10 insertions(+), 5 deletions(-)
wcs/publisher.py
114 114
    def register_cronjobs(cls):
115 115
        super(WcsPublisher, cls).register_cronjobs()
116 116
        # every hour: check for global action timeouts
117
        cls.register_cronjob(CronJob(cls.apply_global_action_timeouts,
118
            minutes=[random.randint(0, 59)]))
117
        cls.register_cronjob(CronJob(cls.apply_global_action_timeouts, hourly=True))
119 118

  
120 119
    def is_using_postgresql(self):
121 120
        return bool(self.has_site_option('postgresql') and self.cfg.get('postgresql', {}))
wcs/qommon/cron.py
16 16

  
17 17
import sys
18 18

  
19
from django.conf import settings
20

  
19 21
class CronJob(object):
20 22
    hours = None
21 23
    minutes = None
......
23 25
    days = None
24 26
    function = None
25 27

  
26
    def __init__(self, function, hours = None, minutes = None, weekdays = None, days = None):
28
    def __init__(self, function, hours=None, minutes=None, weekdays=None, days=None, hourly=False):
27 29
        self.function = function
28 30
        self.hours = hours
29 31
        self.minutes = minutes
30 32
        self.weekdays = weekdays
31 33
        self.days = days
34
        if hourly:
35
            # set minutes to an arbitrary value based on installation, this
36
            # prevents waking up all jobs at the same time on a server farm.
37
            self.minutes = [ord(settings.SECRET_KEY[-1]) % 60]
32 38

  
33 39
def cron_worker(publisher, now):
34 40
    try:
wcs/qommon/publisher.py
740 740
    def register_cronjobs(cls):
741 741
        cls.register_cronjob(CronJob(cls.clean_sessions, minutes=range(0, 60, 5)))
742 742
        cls.register_cronjob(CronJob(cls.clean_nonces, minutes=range(0, 60, 5)))
743
        cls.register_cronjob(CronJob(cls.clean_afterjobs, minutes=[random.randint(0, 59)]))
744
        cls.register_cronjob(CronJob(cls.clean_tempfiles, minutes=[random.randint(0, 59)]))
743
        cls.register_cronjob(CronJob(cls.clean_afterjobs, hourly=True))
744
        cls.register_cronjob(CronJob(cls.clean_tempfiles, hourly=True))
745 745

  
746 746
    register_tld_names = False
747 747

  
748
-