diff --git a/command/plan.go b/command/plan.go index 896e5f77ddf5..a9fab5fdef65 100644 --- a/command/plan.go +++ b/command/plan.go @@ -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) diff --git a/command/run.go b/command/run.go index a5eeb58082e5..7fd87ba27ae4 100644 --- a/command/run.go +++ b/command/run.go @@ -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) diff --git a/command/status.go b/command/status.go index a9543feff664..bf56808138ee 100644 --- a/command/status.go +++ b/command/status.go @@ -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) @@ -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 diff --git a/nomad/periodic.go b/nomad/periodic.go index a629427a73c5..7d4e324580b7 100644 --- a/nomad/periodic.go +++ b/nomad/periodic.go @@ -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())) diff --git a/nomad/periodic_test.go b/nomad/periodic_test.go index bcc5282c3037..4b858c419f88 100644 --- a/nomad/periodic_test.go +++ b/nomad/periodic_test.go @@ -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()