0001-ctl-add-raise-argument-to-runjob-command-68028.patch
tests/test_ctl.py | ||
---|---|---|
437 | 437 |
self.l10n_month = WorkflowStatusItem().compute('{{ "10/10/2010"|date:"F" }}') |
438 | 438 | |
439 | 439 | |
440 |
class TestExceptionAfterJob(AfterJob): |
|
441 |
def execute(self): |
|
442 |
raise ZeroDivisionError() |
|
443 | ||
444 | ||
440 | 445 |
def test_runjob(pub): |
441 | 446 |
with pytest.raises(CommandError): |
442 | 447 |
call_command('runjob') |
... | ... | |
476 | 481 |
call_command('runjob', '--domain=example.net', '--job-id=%s' % job.id, '--force-replay') |
477 | 482 |
assert AfterJob.get(job.id).completion_time != completion_time |
478 | 483 | |
484 |
# test exception handling |
|
485 |
job = TestExceptionAfterJob(label='test3') |
|
486 |
job.store() |
|
487 |
assert AfterJob.get(job.id).status == 'registered' |
|
488 |
call_command('runjob', '--domain=example.net', '--job-id=%s' % job.id) |
|
489 |
assert AfterJob.get(job.id).status == 'failed' |
|
490 |
assert 'ZeroDivisionError' in AfterJob.get(job.id).exception |
|
491 | ||
492 |
# check --raise |
|
493 |
with pytest.raises(ZeroDivisionError): |
|
494 |
call_command('runjob', '--domain=example.net', '--job-id=%s' % job.id, '--force-replay', '--raise') |
|
495 | ||
479 | 496 | |
480 | 497 |
def test_ctl_print_help(capsys): |
481 | 498 |
ctl = wcs.qommon.ctl.Ctl(cmd_prefixes=['wcs.ctl']) |
wcs/ctl/management/commands/runjob.py | ||
---|---|---|
28 | 28 |
parser.add_argument('--domain', action='store', required=True) |
29 | 29 |
parser.add_argument('--job-id', action='store', required=True) |
30 | 30 |
parser.add_argument('--force-replay', action='store_true', default=False) |
31 |
parser.add_argument('--raise', action='store_true', default=False) |
|
31 | 32 | |
32 | 33 |
def handle(self, *args, **options): |
33 | 34 |
domain = options.pop('domain') |
... | ... | |
38 | 39 |
raise CommandError('missing job') |
39 | 40 |
if options.get('force_replay'): |
40 | 41 |
job.completion_time = None |
42 |
job.raise_exception = options.get('raise') |
|
41 | 43 |
job.run() |
wcs/qommon/afterjobs.py | ||
---|---|---|
117 | 117 |
else: |
118 | 118 |
self.job_cmd(job=self) |
119 | 119 |
except Exception as e: |
120 |
if getattr(self, 'raise_exception', False): |
|
121 |
raise |
|
120 | 122 |
get_publisher().record_error(exception=e, notify=True) |
121 | 123 |
self.exception = traceback.format_exc() |
122 | 124 |
self.status = N_('failed') |
123 |
- |