Skip to content

Commit

Permalink
Merge pull request #2385 from hashicorp/f-periodic-paramaterized
Browse files Browse the repository at this point in the history
Handle periodic paramaterized jobs
  • Loading branch information
dadgar committed Mar 1, 2017
2 parents 7a24146 + 8538770 commit a6d7dd3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion command/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func formatDryRun(resp *api.JobPlanResponse, job *api.Job) string {
out += fmt.Sprintf("[green]- Rolling update, next evaluation will be in %s.\n", rolling.Wait)
}

if next := resp.NextPeriodicLaunch; !next.IsZero() {
if next := resp.NextPeriodicLaunch; !next.IsZero() && !job.IsParameterized() {
loc, err := job.Periodic.GetLocation()
if err != nil {
out += fmt.Sprintf("[yellow]- Invalid time zone: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion command/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ OUTSIDE:
// Check if we should enter monitor mode
if detach || periodic || paramjob {
c.Ui.Output("Job registration successful")
if periodic {
if periodic && !paramjob {
loc, err := job.Periodic.GetLocation()
if err == nil {
now := time.Now().In(loc)
Expand Down
4 changes: 2 additions & 2 deletions command/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (c *StatusCommand) Run(args []string) int {
fmt.Sprintf("Parameterized|%v", parameterized),
}

if periodic {
if periodic && !parameterized {
location, err := job.Periodic.GetLocation()
if err == nil {
now := time.Now().In(location)
Expand All @@ -165,7 +165,7 @@ func (c *StatusCommand) Run(args []string) int {
}

// Print periodic job information
if periodic {
if periodic && !parameterized {
if err := c.outputPeriodicInfo(client, job); err != nil {
c.Ui.Error(err.Error())
return 1
Expand Down
6 changes: 6 additions & 0 deletions nomad/periodic.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ func (p *PeriodicDispatch) Add(job *structs.Job) error {
return nil
}

// Check if the job is also a parameterized job. If it is, then we do not want to
// treat it as a periodic job but only its dispatched children.
if job.IsParameterized() {
return nil
}

// Add or update the job.
p.tracked[job.ID] = job
next := job.Periodic.Next(time.Now().In(job.Periodic.GetLocation()))
Expand Down
14 changes: 14 additions & 0 deletions nomad/periodic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ func TestPeriodicDispatch_Add_NonPeriodic(t *testing.T) {
}
}

func TestPeriodicDispatch_Add_Periodic_Parameterized(t *testing.T) {
p, _ := testPeriodicDispatcher()
job := mock.PeriodicJob()
job.ParameterizedJob = &structs.ParameterizedJobConfig{}
if err := p.Add(job); err != nil {
t.Fatalf("Add of periodic parameterized job failed: %v; expect no-op", err)
}

tracked := p.Tracked()
if len(tracked) != 0 {
t.Fatalf("Add of periodic parameterized job should be no-op: %v", tracked)
}
}

func TestPeriodicDispatch_Add_UpdateJob(t *testing.T) {
p, _ := testPeriodicDispatcher()
job := mock.PeriodicJob()
Expand Down

0 comments on commit a6d7dd3

Please sign in to comment.