Use desired launch time in periodic launch table

This commit is contained in:
Alex Dadgar
2015-12-23 18:22:16 -08:00
parent 0186d55773
commit bbae488b70
2 changed files with 11 additions and 5 deletions

View File

@@ -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

View File

@@ -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()
@@ -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)
}
}