Projet

Général

Profil

0001-general-add-explicit-registration-of-cron-jobs-52793.patch

Frédéric Péters, 06 avril 2021 19:04

Télécharger (6,34 ko)

Voir les différences:

Subject: [PATCH] general: add explicit registration of cron jobs (#52793)

 tests/test_publisher.py      |  2 +-
 wcs/data_sources.py          |  2 +-
 wcs/formdef.py               |  2 +-
 wcs/publisher.py             | 15 ++++-----------
 wcs/qommon/ident/password.py |  2 +-
 wcs/qommon/publisher.py      |  5 +++++
 wcs/wf/aggregation_email.py  |  2 +-
 wcs/wf/jump.py               |  2 +-
 wcs/workflows.py             |  3 +++
 9 files changed, 18 insertions(+), 17 deletions(-)
tests/test_publisher.py
161 161

  
162 162

  
163 163
def test_register_cronjobs():
164
    assert not pub.cronjobs
165 164
    pub.register_cronjobs()
166 165
    assert 'apply_global_action_timeouts' in [x.function.__name__ for x in pub.cronjobs]
167 166
    assert 'clean_sessions' in [x.function.__name__ for x in pub.cronjobs]
167
    assert 'evaluate_jumps' in [x.name for x in pub.cronjobs]
168 168

  
169 169

  
170 170
def test_get_default_position():
wcs/data_sources.py
890 890
        build_agenda_datasources(get_publisher())
891 891

  
892 892

  
893
if get_publisher_class():
893
def register_cronjob():
894 894
    # every hour: check for agenda datasources
895 895
    get_publisher_class().register_cronjob(
896 896
        CronJob(build_agenda_datasources, name='build_agenda_datasources', minutes=[0])
wcs/formdef.py
1781 1781
    return formdefs
1782 1782

  
1783 1783

  
1784
if get_publisher_class():
1784
def register_cronjobs():
1785 1785
    # once a day, look for:
1786 1786
    # * expired drafts
1787 1787
    get_publisher_class().register_cronjob(CronJob(clean_drafts, name='clean_drafts', hours=[2], minutes=[0]))
wcs/publisher.py
27 27

  
28 28
from wcs.qommon import force_str
29 29

  
30
from . import custom_views, sessions
30
from . import custom_views, data_sources, formdef, sessions
31 31
from .admin import RootDirectory as AdminRootDirectory
32 32
from .backoffice import RootDirectory as BackofficeRootDirectory
33 33
from .Defaults import *  # noqa pylint: disable=wildcard-import
......
44 44
    pass
45 45

  
46 46

  
47
# this is terribly ugly but import RootDirectory will import a bunch of things,
48
# and some of them need a publisher to be set
49
class StubWcsPublisher(QommonPublisher):
50
    pass
51

  
52

  
53
set_publisher_class(StubWcsPublisher)
54

  
55

  
56 47
class UnpicklerClass(pickle.Unpickler):
57 48
    def find_class(self, module, name):
58 49
        if module == 'qommon.form':
......
69 60
        return klass
70 61

  
71 62

  
72
class WcsPublisher(StubWcsPublisher):
63
class WcsPublisher(QommonPublisher):
73 64
    APP_NAME = 'wcs'
74 65
    APP_DIR = APP_DIR
75 66
    DATA_DIR = DATA_DIR
......
125 116
        cls.register_cronjob(
126 117
            CronJob(cls.apply_global_action_timeouts, name='evaluate_global_action_timeouts', minutes=[0])
127 118
        )
119
        data_sources.register_cronjob()
120
        formdef.register_cronjobs()
128 121

  
129 122
    def is_using_postgresql(self):
130 123
        return bool(self.has_site_option('postgresql') and self.cfg.get('postgresql', {}))
wcs/qommon/ident/password.py
1423 1423
            token.remove_self()
1424 1424

  
1425 1425

  
1426
if get_publisher_class():
1426
def register_cronjobs():
1427 1427
    # at 6:00 in the morning, every day
1428 1428
    get_publisher_class().register_cronjob(CronJob(handle_unused_accounts, minutes=[0], hours=[6]))
1429 1429
    get_publisher_class().register_cronjob(CronJob(handle_expired_tokens, minutes=[0], hours=[6]))
wcs/qommon/publisher.py
540 540
        from .ident import password
541 541

  
542 542
        classes.append(password.PasswordAuthMethod)
543
        password.register_cronjobs()
544

  
543 545
        self.ident_methods = {}
544 546
        for klass in classes:
545 547
            self.ident_methods[klass.key] = klass
......
551 553
    def register_cronjob(cls, cronjob):
552 554
        if not cls.cronjobs:
553 555
            cls.cronjobs = []
556
        if cronjob.name and any(x for x in cls.cronjobs if x.name == cronjob.name):
557
            # already registered
558
            return
554 559
        cls.cronjobs.append(cronjob)
555 560

  
556 561
    def clean_nonces(self, delta=60, now=None):
wcs/wf/aggregation_email.py
163 163
        emails.email(mail_subject, body, email_rcpt=role.get_emails())
164 164

  
165 165

  
166
if get_publisher_class():
166
def register_cronjob():
167 167
    # at 6:00 in the morning, every day but the week end
168 168
    get_publisher_class().register_cronjob(
169 169
        CronJob(
wcs/wf/jump.py
328 328
                        break
329 329

  
330 330

  
331
if get_publisher_class():
331
def register_cronjob():
332 332
    # every JUMP_TIMEOUT_INTERVAL minutes check for expired status jump
333 333
    # timeouts.
334 334
    get_publisher_class().register_cronjob(
wcs/workflows.py
3333 3333
    from .wf import timeout_jump  # noqa pylint: disable=unused-import
3334 3334
    from .wf import wscall  # noqa pylint: disable=unused-import
3335 3335

  
3336
    aggregation_email.register_cronjob()
3337
    jump.register_cronjob()
3338

  
3336 3339

  
3337 3340
from .wf.export_to_model import ExportToModel  # noqa pylint: disable=unused-import,wrong-import-position
3338
-