Skip to content

Commit

Permalink
Merge pull request #1074 from hashicorp/f-periodic-utc
Browse files Browse the repository at this point in the history
Periodic jobs always are evaluated in UTC TZ
  • Loading branch information
dadgar committed Apr 13, 2016
2 parents d1e3585 + b63f3bb commit 16bd0fa
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion command/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion command/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions nomad/periodic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion website/source/docs/jobspec/index.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion website/source/docs/jobspec/json.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 16bd0fa

Please sign in to comment.