Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasell committed Mar 21, 2023
1 parent a633b79 commit 7f5b240
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
7 changes: 5 additions & 2 deletions nomad/leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion nomad/periodic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions nomad/periodic_endpoint.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nomad

import (
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7f5b240

Please sign in to comment.