Show reschedule policy in addition to when the eval will get rescheduled

This commit is contained in:
Preetha Appan 2018-03-20 13:34:29 -05:00
parent ec13089be9
commit 30fff15de7
No known key found for this signature in database
GPG Key ID: 9F7C19990A50EAFC
4 changed files with 27 additions and 5 deletions

View File

@ -648,6 +648,16 @@ func (j *Job) Canonicalize() {
}
}
// LookupTaskGroup finds a task group by name
func (j *Job) LookupTaskGroup(name string) *TaskGroup {
for _, tg := range j.TaskGroups {
if *tg.Name == name {
return tg
}
}
return nil
}
// JobSummary summarizes the state of the allocations of a job
type JobSummary struct {
JobID string

View File

@ -132,6 +132,17 @@ func (r *ReschedulePolicy) Copy() *ReschedulePolicy {
return nrp
}
func (p *ReschedulePolicy) String() string {
if p == nil {
return ""
}
if *p.Unlimited {
return fmt.Sprintf("unlimited with %v delay, max_delay = %v", *p.DelayFunction, *p.MaxDelay)
} else {
return fmt.Sprintf("%v in %v with %v delay, max_delay = %v", *p.Attempts, *p.Interval, *p.DelayFunction, *p.MaxDelay)
}
}
// CheckRestart describes if and when a task should be restarted based on
// failing health checks.
type CheckRestart struct {

View File

@ -371,7 +371,7 @@ func (c *JobStatusCommand) outputJobInfo(client *api.Client, job *api.Job) error
c.outputFailedPlacements(latestFailedPlacement)
}
c.outputReschedulingEvals(client, jobAllocs)
c.outputReschedulingEvals(client, job, jobAllocs, c.length)
if latestDeployment != nil {
c.Ui.Output(c.Colorize().Color("\n[bold]Latest Deployment[reset]"))
@ -540,7 +540,7 @@ func (c *JobStatusCommand) outputJobSummary(client *api.Client, job *api.Job) er
// outputReschedulingEvals displays eval IDs and time for any
// delayed evaluations by task group
func (c *JobStatusCommand) outputReschedulingEvals(client *api.Client, allocListStubs []*api.AllocationListStub) error {
func (c *JobStatusCommand) outputReschedulingEvals(client *api.Client, job *api.Job, allocListStubs []*api.AllocationListStub, uuidLength int) error {
// Get the most recent alloc ID by task group
mostRecentAllocs := make(map[string]*api.AllocationListStub)
@ -579,11 +579,12 @@ func (c *JobStatusCommand) outputReschedulingEvals(client *api.Client, allocList
if err != nil || evaluation.WaitUntil.IsZero() || time.Now().After(evaluation.WaitUntil) {
continue
}
rp := job.LookupTaskGroup(taskGroup).ReschedulePolicy
evalTime := prettyTimeDiff(evaluation.WaitUntil, time.Now())
evalDetails = append(evalDetails, fmt.Sprintf("%s|%s|%s", taskGroup, evalID, evalTime))
evalDetails = append(evalDetails, fmt.Sprintf("%s|%s|%s|%s", taskGroup, rp.String(), limit(evalID, uuidLength), evalTime))
}
if len(evalDetails) > 0 { // Only show this section if there is pending evals
delayedEvalInfos = append(delayedEvalInfos, "Task Group|Eval ID|Eval Time")
delayedEvalInfos = append(delayedEvalInfos, "Task Group|Reschedule Policy|Eval ID|Eval Time")
delayedEvalInfos = append(delayedEvalInfos, evalDetails...)
c.Ui.Output(c.Colorize().Color("\n[bold]Upcoming Evaluations[reset]"))
c.Ui.Output(formatList(delayedEvalInfos))

View File

@ -331,7 +331,7 @@ func TestJobStatusCommand_RescheduleEvals(t *testing.T) {
}
out := ui.OutputWriter.String()
require.Contains(out, "Upcoming Evaluations")
require.Contains(out, e.ID)
require.Contains(out, e.ID[:8])
}
func waitForSuccess(ui cli.Ui, client *api.Client, length int, t *testing.T, evalId string) int {