From b63f3bb0784b2ad427ce0979c144e476d44f8f8a Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 12 Apr 2016 09:47:25 -0700 Subject: [PATCH] Periodic jobs always are evaluated in UTC TZ --- command/run.go | 2 +- command/status.go | 2 +- nomad/periodic.go | 6 +++--- website/source/docs/jobspec/index.html.md | 4 +++- website/source/docs/jobspec/json.html.md | 4 +++- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/command/run.go b/command/run.go index 8a8968f69b5..f5745f7aa7a 100644 --- a/command/run.go +++ b/command/run.go @@ -146,7 +146,7 @@ func (c *RunCommand) Run(args []string) int { if detach || periodic { c.Ui.Output("Job registration successful") if periodic { - c.Ui.Output(fmt.Sprintf("Approximate next launch time: %v", job.Periodic.Next(time.Now()))) + c.Ui.Output(fmt.Sprintf("Approximate next launch time: %v", job.Periodic.Next(time.Now().UTC()))) } else { c.Ui.Output("Evaluation ID: " + evalID) } diff --git a/command/status.go b/command/status.go index 83ef361c7ca..9eedf966a77 100644 --- a/command/status.go +++ b/command/status.go @@ -155,7 +155,7 @@ func (c *StatusCommand) Run(args []string) int { if periodic { basic = append(basic, fmt.Sprintf("Next Periodic Launch|%v", - sJob.Periodic.Next(time.Now()))) + sJob.Periodic.Next(time.Now().UTC()))) } c.Ui.Output(formatKV(basic)) diff --git a/nomad/periodic.go b/nomad/periodic.go index ccbdd809d7d..97e1b24523f 100644 --- a/nomad/periodic.go +++ b/nomad/periodic.go @@ -203,7 +203,7 @@ func (p *PeriodicDispatch) Add(job *structs.Job) error { // Add or update the job. p.tracked[job.ID] = job - next := job.Periodic.Next(time.Now()) + next := job.Periodic.Next(time.Now().UTC()) if tracked { if err := p.heap.Update(job, next); err != nil { return fmt.Errorf("failed to update job %v launch time: %v", job.ID, err) @@ -281,7 +281,7 @@ func (p *PeriodicDispatch) ForceRun(jobID string) (*structs.Evaluation, error) { } p.l.Unlock() - return p.createEval(job, time.Now()) + return p.createEval(job, time.Now().UTC()) } // shouldRun returns whether the long lived run function should run. @@ -301,7 +301,7 @@ func (p *PeriodicDispatch) run() { if launch.IsZero() { launchCh = nil } else { - launchDur := launch.Sub(time.Now()) + launchDur := launch.Sub(time.Now().UTC()) launchCh = time.After(launchDur) p.logger.Printf("[DEBUG] nomad.periodic: launching job %q in %s", job.ID, launchDur) } diff --git a/website/source/docs/jobspec/index.html.md b/website/source/docs/jobspec/index.html.md index 17199be93fa..1807272c797 100644 --- a/website/source/docs/jobspec/index.html.md +++ b/website/source/docs/jobspec/index.html.md @@ -174,7 +174,9 @@ The `job` object supports the following keys: ``` * `periodic` - `periodic` allows the job to be scheduled at fixed times, dates - or intervals. The `periodic` block supports the following keys: + or intervals. The periodic expression is always evaluated in the UTC + timezone to ensure consistent evaluation when Nomad Servers span multiple + time zones. The `periodic` block supports the following keys: * `enabled` - `enabled` determines whether the periodic job will spawn child jobs. `enabled` is defaulted to true if the block is included. diff --git a/website/source/docs/jobspec/json.html.md b/website/source/docs/jobspec/json.html.md index bfdbde4c5ca..91834146ca6 100644 --- a/website/source/docs/jobspec/json.html.md +++ b/website/source/docs/jobspec/json.html.md @@ -189,7 +189,9 @@ The `Job` object supports the following keys: ``` * `Periodic` - `Periodic` allows the job to be scheduled at fixed times, dates - or intervals. The `Periodic` object supports the following attributes: + or intervals. The periodic expression is always evaluated in the UTC + timezone to ensure consistent evaluation when Nomad Servers span multiple + time zones. The `Periodic` object supports the following attributes: * `Enabled` - `Enabled` determines whether the periodic job will spawn child jobs.