0001-cron-add-a-option-to-target-domain-44188.patch
tests/test_publisher.py | ||
---|---|---|
198 | 198 |
gettempdir.side_effect = lambda: pub.app_dir |
199 | 199 | |
200 | 200 |
with mock.patch('wcs.qommon.management.commands.cron.cron_worker') as cron_worker: |
201 |
call_command('cron') |
|
202 |
assert cron_worker.call_count == 1 |
|
201 |
with mock.patch('wcs.qommon.publisher.QommonPublisher.get_tenants') as mock_tenants: |
|
202 |
mock_tenants.return_value = ['example.net', 'foo.bar', 'something.com'] |
|
203 |
call_command('cron') |
|
204 |
assert cron_worker.call_count == 3 |
|
205 |
cron_worker.reset_mock() |
|
206 |
call_command('cron', domain='example.net') |
|
207 |
assert cron_worker.call_count == 1 |
|
203 | 208 | |
204 | 209 |
# simulate another locked cron |
205 | 210 |
from wcs.qommon.vendor import locket |
wcs/qommon/management/commands/cron.py | ||
---|---|---|
34 | 34 | |
35 | 35 |
def add_arguments(self, parser): |
36 | 36 |
parser.set_defaults(verbosity=0) |
37 |
parser.add_argument('-d', '--domain', '--vhost', metavar='DOMAIN') |
|
37 | 38 |
parser.add_argument('--force-job', dest='force_job', action='store_true', |
38 | 39 |
help='Run even if DISABLE_CRON_JOBS is set in settings') |
39 | 40 |
parser.add_argument('--job', dest='job_name', metavar='NAME') |
... | ... | |
44 | 45 |
print('Command is ignored because DISABLE_CRON_JOBS is set in settings') |
45 | 46 |
return |
46 | 47 |
lockfile = os.path.join(tempfile.gettempdir(), 'wcs-cron-in-progress.lock') |
48 |
if options.get('domain'): |
|
49 |
domains = [options.get('domain')] |
|
50 |
else: |
|
51 |
domains = get_publisher_class().get_tenants() |
|
47 | 52 |
try: |
48 | 53 |
with locket.lock_file(lockfile, timeout=0): |
49 | 54 |
if verbosity > 2: |
... | ... | |
53 | 58 |
publisher_class.register_cronjobs() |
54 | 59 |
publisher = publisher_class.create_publisher() |
55 | 60 |
app_dir = publisher.app_dir |
56 |
for hostname in publisher.get_tenants():
|
|
61 |
for hostname in domains:
|
|
57 | 62 |
if verbosity > 1: |
58 | 63 |
print('cron work on %s' % hostname) |
59 | 64 |
publisher.app_dir = os.path.join(app_dir, hostname) |
60 |
- |