Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle periodic paramaterized jobs #2385

Merged
merged 2 commits into from
Mar 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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