Don't restore parameterized periodic jobs

This commit is contained in:
Alex Dadgar 2017-08-03 12:37:58 -07:00
parent c08e244e43
commit 146f3f5cb2
3 changed files with 26 additions and 8 deletions

View File

@ -71,8 +71,7 @@ RECONCILE:
// Check if we need to handle initial leadership actions
if !establishedLeader {
if err := s.establishLeadership(stopCh); err != nil {
s.logger.Printf("[ERR] nomad: failed to establish leadership: %v",
err)
s.logger.Printf("[ERR] nomad: failed to establish leadership: %v", err)
goto WAIT
}
establishedLeader = true
@ -288,6 +287,13 @@ func (s *Server) restorePeriodicDispatcher() error {
now := time.Now()
for i := iter.Next(); i != nil; i = iter.Next() {
job := i.(*structs.Job)
// We skip adding parameterized jobs because they themselves aren't
// tracked, only the dispatched children are.
if job.IsParameterized() {
continue
}
s.periodicDispatcher.Add(job)
// If the periodic job has never been launched before, launch will hold

View File

@ -328,10 +328,12 @@ func TestLeader_PeriodicDispatcher_Restore_Adds(t *testing.T) {
t.Fatalf("Should have a leader")
}
// Inject a periodic job and non-periodic job
// Inject a periodic job, a parameterized periodic job and a non-periodic job
periodic := mock.PeriodicJob()
nonPeriodic := mock.Job()
for _, job := range []*structs.Job{nonPeriodic, periodic} {
parameterizedPeriodic := mock.PeriodicJob()
parameterizedPeriodic.ParameterizedJob = &structs.ParameterizedJobConfig{}
for _, job := range []*structs.Job{nonPeriodic, periodic, parameterizedPeriodic} {
req := structs.JobRegisterRequest{
Job: job,
}
@ -359,12 +361,20 @@ func TestLeader_PeriodicDispatcher_Restore_Adds(t *testing.T) {
t.Fatalf("should have leader")
})
// Check that the new leader is tracking the periodic job.
// Check that the new leader is tracking the periodic job only
testutil.WaitForResult(func() (bool, error) {
_, tracked := leader.periodicDispatcher.tracked[periodic.ID]
return tracked, nil
if _, tracked := leader.periodicDispatcher.tracked[periodic.ID]; !tracked {
return false, fmt.Errorf("periodic job not tracked")
}
if _, tracked := leader.periodicDispatcher.tracked[nonPeriodic.ID]; tracked {
return false, fmt.Errorf("non periodic job tracked")
}
if _, tracked := leader.periodicDispatcher.tracked[parameterizedPeriodic.ID]; tracked {
return false, fmt.Errorf("parameterized periodic job tracked")
}
return true, nil
}, func(err error) {
t.Fatalf("periodic job not tracked")
t.Fatalf(err.Error())
})
}

View File

@ -164,11 +164,13 @@ func (p *PeriodicDispatch) SetEnabled(enabled bool) {
}
}
// TODO Why have a seperate start method
// Start begins the goroutine that creates derived jobs and evals.
func (p *PeriodicDispatch) Start() {
p.l.Lock()
p.running = true
p.l.Unlock()
// XXX There must be two insances of the run routine
go p.run()
}