Allow Passing of Jitter Values in TimerDriver

For periodic pipelines to not all trigger at the same moment and thus
potentially bear a lot of load on a system, we could spread the trigger
times by a jitter value. The APScheduler library Zuul uses for timer
triggers supports such jitter values.
This change allows one to pass that jitter value within the cron-like
'time' parameter of the timer trigger.
The optional Jitter parameter can be passed as the last parameter after
the optional 'seconds'.

Change-Id: I58e756dff6251b49a972b26f7a3a49a8ee5aa70e
This commit is contained in:
Benjamin Schanzel
2020-01-16 13:07:41 +01:00
parent ad42c7f570
commit 612472b9e3
4 changed files with 81 additions and 7 deletions

View File

@@ -61,7 +61,7 @@ class TimerDriver(Driver, TriggerInterface):
continue
for timespec in ef.timespecs:
parts = timespec.split()
if len(parts) < 5 or len(parts) > 6:
if len(parts) < 5 or len(parts) > 7:
self.log.error(
"Unable to parse time value '%s' "
"defined in pipeline %s" % (
@@ -69,15 +69,21 @@ class TimerDriver(Driver, TriggerInterface):
pipeline.name))
continue
minute, hour, dom, month, dow = parts[:5]
# default values
second = None
jitter = None
if len(parts) > 5:
second = parts[5]
else:
second = None
if len(parts) > 6:
jitter = parts[6]
try:
jitter = int(jitter) if jitter is not None else None
trigger = CronTrigger(day=dom, day_of_week=dow,
hour=hour, minute=minute,
second=second)
second=second, jitter=jitter)
except ValueError:
self.log.exception(
"Unable to create CronTrigger "