From c741cb3a268f449dd0782f289b066eb861dd408d Mon Sep 17 00:00:00 2001 From: Aaron Meihm Date: Thu, 17 Sep 2015 23:21:59 -0500 Subject: [PATCH] [minor] improve flexibility for action expiry handling Allows jobs to specify the expiry time that is desired for the action in the configuration file. This also handles increasing the window based on the job validity time being set in the past. --- mig-runner/entity.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/mig-runner/entity.go b/mig-runner/entity.go index e39943ba..cd2b4bec 100644 --- a/mig-runner/entity.go +++ b/mig-runner/entity.go @@ -15,6 +15,10 @@ import ( "time" ) +// The default expiry time for an action launched by the runner if the +// entity configuration does not include an expiry. +var defaultExpiry = "5m" + type entity struct { name string baseDir string @@ -30,6 +34,7 @@ type entityConfig struct { Configuration struct { Schedule string Plugin string + Expiry string } } @@ -62,12 +67,21 @@ func (e *entity) launchAction() (err error) { panic(err) } - // Borrow some logic from the action generator. - act.ValidFrom = time.Now().Add(-60 * time.Second).UTC() - period, err := time.ParseDuration("2m") + // Borrow some logic from the action generator. Set a validation + // period starting in the past so our action starts immediately. + window := time.Duration(-60 * time.Second) + act.ValidFrom = time.Now().Add(window).UTC() + exstring := defaultExpiry + if e.cfg.Configuration.Expiry != "" { + exstring = e.cfg.Configuration.Expiry + } + period, err := time.ParseDuration(exstring) if err != nil { panic(err) } + // Add the window period to the desired expiry since our start + // time begins in the past. + period += -window act.ExpireAfter = act.ValidFrom.Add(period) asig, err := cli.SignAction(act) if err != nil {