Skip to content

Commit

Permalink
Use desired launch time in periodic launch table
Browse files Browse the repository at this point in the history
  • Loading branch information
dadgar committed Dec 24, 2015
1 parent 0186d55 commit bbae488
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion nomad/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,13 @@ func (n *nomadFSM) applyUpsertJob(buf []byte, index uint64) interface{} {
}

if parent.IsPeriodic() {
launch := &structs.PeriodicLaunch{ID: parentID, Launch: time.Now()}
t, err := n.periodicDispatcher.LaunchTime(req.Job.ID)
if err != nil {
n.logger.Printf("[ERR] nomad.fsm: LaunchTime(%v) failed: %v", req.Job.ID, err)
return err
}

launch := &structs.PeriodicLaunch{ID: parentID, Launch: t}
if err := n.state.UpsertPeriodicLaunch(index, launch); err != nil {
n.logger.Printf("[ERR] nomad.fsm: UpsertPeriodicLaunch failed: %v", err)
return err
Expand Down
8 changes: 4 additions & 4 deletions nomad/leader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,13 @@ func TestLeader_PeriodicDispatcher_Restore_NoEvals(t *testing.T) {
// Flush the periodic dispatcher, ensuring that no evals will be created.
s1.periodicDispatcher.SetEnabled(false)

// Sleep till after the job should have been launched.
time.Sleep(3 * time.Second)

// Get the current time to ensure the launch time is after this once we
// restore.
now := time.Now()

// Sleep till after the job should have been launched.
time.Sleep(3 * time.Second)

// Restore the periodic dispatcher.
s1.periodicDispatcher.SetEnabled(true)
s1.periodicDispatcher.Start()
Expand All @@ -412,7 +412,7 @@ func TestLeader_PeriodicDispatcher_Restore_NoEvals(t *testing.T) {
}

if last.Launch.Before(now) {
t.Fatalf("restorePeriodicDispatcher did not force launch")
t.Fatalf("restorePeriodicDispatcher did not force launch: last %v; want after %v", last.Launch, now)
}
}

Expand Down

0 comments on commit bbae488

Please sign in to comment.