Merge pull request #2385 from hashicorp/f-periodic-paramaterized

Handle periodic paramaterized jobs
This commit is contained in:
Alex Dadgar
2017-03-01 14:52:56 -08:00
committed by GitHub
5 changed files with 24 additions and 4 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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()))

View File

@@ -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()