Projet

Général

Profil

0001-cron-enable-DISABLE_CRON_JOBS-for-a-specific-tenant-.patch

Emmanuel Cazenave, 28 septembre 2021 13:09

Télécharger (2,52 ko)

Voir les différences:

Subject: [PATCH] cron: enable DISABLE_CRON_JOBS for a specific tenant (#56597)

 tests/test_publisher.py                | 16 ++++++++++++++++
 wcs/qommon/management/commands/cron.py |  6 +++++-
 2 files changed, 21 insertions(+), 1 deletion(-)
tests/test_publisher.py
234 234
                cron_worker.reset_mock()
235 235
                call_command('cron', domain='example.net')
236 236
                assert cron_worker.call_count == 1
237
                cron_worker.reset_mock()
238

  
239
                # disable cron on something.com
240
                site_options_path = os.path.join(pub.APP_DIR, 'something.com', 'site-options.cfg')
241
                with open(site_options_path, 'w') as fd:
242
                    fd.write(
243
                        '''\
244
                        [variables]
245
                        disable_cron_jobs = True
246
                        '''
247
                    )
248

  
249
                call_command('cron')
250
                assert cron_worker.call_count == 2
251
                cron_worker.reset_mock()
252
                os.unlink(site_options_path)
237 253

  
238 254
        # simulate another locked cron
239 255
        from wcs.qommon.vendor import locket
wcs/qommon/management/commands/cron.py
60 60
                publisher_class.register_cronjobs()
61 61
                publisher = publisher_class.create_publisher()
62 62
                for hostname in domains:
63
                    publisher.set_tenant_by_hostname(hostname)
64
                    if publisher.get_site_option('disable_cron_jobs', 'variables'):
65
                        if verbosity > 1:
66
                            print('cron ignored on %s because DISABLE_CRON_JOBS is set' % hostname)
67
                        continue
63 68
                    if verbosity > 1:
64 69
                        print('cron work on %s' % hostname)
65
                    publisher.set_tenant_by_hostname(hostname)
66 70
                    cron_worker(publisher, now, job_name=options.get('job_name'))
67 71
            if verbosity > 2:
68 72
                print('cron end (release lock %s)' % lockfile)
69
-