@jippi Changed my mind! Good suggestion

This commit is contained in:
Alex Dadgar 2017-07-06 23:04:32 -07:00
parent e6f5e3f301
commit ade9a7c768
5 changed files with 15 additions and 8 deletions

View file

@ -473,12 +473,13 @@ func (t *Task) SetLogConfig(l *LogConfig) *Task {
// TaskState tracks the current state of a task and events that caused state
// transitions.
type TaskState struct {
State string
Failed bool
Restarts uint64
StartedAt time.Time
FinishedAt time.Time
Events []*TaskEvent
State string
Failed bool
Restarts uint64
LastRestart time.Time
StartedAt time.Time
FinishedAt time.Time
Events []*TaskEvent
}
const (

View file

@ -584,6 +584,7 @@ func (r *AllocRunner) setTaskState(taskName, state string, event *structs.TaskEv
}
if event.Type == structs.TaskRestarting {
taskState.Restarts++
taskState.LastRestart = time.Unix(0, event.Time)
}
r.appendTaskEvent(taskState, event)
}

View file

@ -280,7 +280,8 @@ func (c *AllocStatusCommand) outputTaskStatus(state *api.TaskState) {
basic := []string{
fmt.Sprintf("Started At|%s", formatTaskTimes(state.StartedAt)),
fmt.Sprintf("Finished At|%s", formatTaskTimes(state.FinishedAt)),
fmt.Sprintf("Total Restarts|%d", state.Restarts)}
fmt.Sprintf("Total Restarts|%d", state.Restarts),
fmt.Sprintf("Last Restart|%s", formatTaskTimes(state.LastRestart))}
c.Ui.Output("Task Events:")
c.Ui.Output(formatKV(basic))

View file

@ -343,7 +343,7 @@ func (c *StatusCommand) outputJobInfo(client *api.Client, job *api.Job) error {
c.outputFailedPlacements(latestFailedPlacement)
}
if latestDeployment != nil && latestDeployment.Status != "successful" {
if latestDeployment != nil {
c.Ui.Output(c.Colorize().Color("\n[bold]Latest Deployment[reset]"))
c.Ui.Output(c.Colorize().Color(c.formatDeployment(latestDeployment)))
}

View file

@ -3337,6 +3337,10 @@ type TaskState struct {
// Restarts is the number of times the task has restarted
Restarts uint64
// LastRestart is the time the task last restarted. It is updated each time the
// task restarts
LastRestart time.Time
// StartedAt is the time the task is started. It is updated each time the
// task starts
StartedAt time.Time