From 7f5b240bc796491832588d9bdb397dff7b31e30b Mon Sep 17 00:00:00 2001 From: James Rasell Date: Tue, 21 Mar 2023 10:29:21 +0000 Subject: [PATCH] WIP --- nomad/leader.go | 7 +++++-- nomad/periodic.go | 17 ++++++++++++++++- nomad/periodic_endpoint.go | 4 ++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/nomad/leader.go b/nomad/leader.go index 97e136219e69..1c1b26334a7b 100644 --- a/nomad/leader.go +++ b/nomad/leader.go @@ -774,11 +774,14 @@ func (s *Server) restorePeriodicDispatcher() error { continue } - if _, err := s.periodicDispatcher.ForceRun(job.Namespace, job.ID); err != nil { + eval, err := s.periodicDispatcher.ForceRun(job.Namespace, job.ID) + if err != nil { logger.Error("force run of periodic job failed", "job", job.NamespacedID(), "error", err) return fmt.Errorf("force run of periodic job %q failed: %v", job.NamespacedID(), err) } - logger.Debug("periodic job force runned during leadership establishment", "job", job.NamespacedID()) + if eval != nil { + logger.Debug("periodic job force ran during leadership establishment", "job", job.NamespacedID()) + } } return nil diff --git a/nomad/periodic.go b/nomad/periodic.go index 5a623f316571..b198655ebfb8 100644 --- a/nomad/periodic.go +++ b/nomad/periodic.go @@ -295,6 +295,21 @@ func (p *PeriodicDispatch) ForceRun(namespace, jobID string) (*structs.Evaluatio return nil, fmt.Errorf("can't force run non-tracked job %q (%s)", jobID, namespace) } + if job.Periodic.ProhibitOverlap { + running, err := p.dispatcher.RunningChildren(job) + if err != nil { + p.logger.Error("failed to determine if periodic job has running children", "job", job.NamespacedID(), "error", err) + p.l.Unlock() + return nil, nil + } + + if running { + p.logger.Debug("skipping launch of periodic job because job prohibits overlap", "job", job.NamespacedID()) + p.l.Unlock() + return nil, nil + } + } + p.l.Unlock() return p.createEval(job, time.Now().In(job.Periodic.GetLocation())) } @@ -367,7 +382,7 @@ func (p *PeriodicDispatch) dispatch(job *structs.Job, launchTime time.Time) { // nextLaunch returns the next job to launch and when it should be launched. If // the next job can't be determined, an error is returned. If the dispatcher is -// stopped, a nil job will be returned. +// stopped, a nil job will be returned. func (p *PeriodicDispatch) nextLaunch() (*structs.Job, time.Time) { // If there is nothing wait for an update. p.l.RLock() diff --git a/nomad/periodic_endpoint.go b/nomad/periodic_endpoint.go index ae8cae2594c0..1522e263f53f 100644 --- a/nomad/periodic_endpoint.go +++ b/nomad/periodic_endpoint.go @@ -1,6 +1,7 @@ package nomad import ( + "errors" "fmt" "time" @@ -72,6 +73,9 @@ func (p *Periodic) Force(args *structs.PeriodicForceRequest, reply *structs.Peri if err != nil { return fmt.Errorf("force launch for job %q failed: %v", job.ID, err) } + if eval == nil { + return errors.New("you're fucking dumb") + } reply.EvalID = eval.ID reply.EvalCreateIndex = eval.CreateIndex