Handle Erroneous Cron Strings in TimerDriver

This change introduces error-handling in case of invalid numeric
values passed to APScheduler's CronTrigger, which fires an unhandeled
ValueError in such a case. Triggers with invalid values will get
ignored, just like tiggers with an invalid 'cron string' (see line 65 of
the same file).

Change-Id: I4fd5d80c0fb3a4fe27a1687c607774eeed3f9db6
This commit is contained in:
Benjamin Schanzel 2020-01-13 16:07:32 +01:00
parent b6160d195f
commit ad42c7f570
2 changed files with 20 additions and 2 deletions

View File

@ -29,3 +29,10 @@
name: org/project2
check:
jobs: []
- pipeline:
name: broken_periodic
manager: independent
trigger:
timer:
time: "*/30 * * * * 300"

View File

@ -73,8 +73,19 @@ class TimerDriver(Driver, TriggerInterface):
second = parts[5]
else:
second = None
trigger = CronTrigger(day=dom, day_of_week=dow, hour=hour,
minute=minute, second=second)
try:
trigger = CronTrigger(day=dom, day_of_week=dow,
hour=hour, minute=minute,
second=second)
except ValueError:
self.log.exception(
"Unable to create CronTrigger "
"for value '%s' defined in "
"pipeline %s",
timespec,
pipeline.name)
continue
job = self.apsched.add_job(
self._onTrigger, trigger=trigger,