From e1c631064a3b336c2bbab7a829c943452df9ce05 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Thu, 6 Jul 2017 23:04:32 -0700 Subject: [PATCH] @jippi Changed my mind! Good suggestion --- api/tasks.go | 13 +++++++------ client/alloc_runner.go | 1 + command/alloc_status.go | 3 ++- command/status.go | 2 +- nomad/structs/structs.go | 4 ++++ 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/api/tasks.go b/api/tasks.go index 1659dd43b..2b59a89fc 100644 --- a/api/tasks.go +++ b/api/tasks.go @@ -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 ( diff --git a/client/alloc_runner.go b/client/alloc_runner.go index efd122627..a54544439 100644 --- a/client/alloc_runner.go +++ b/client/alloc_runner.go @@ -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) } diff --git a/command/alloc_status.go b/command/alloc_status.go index 5a023557f..caef33743 100644 --- a/command/alloc_status.go +++ b/command/alloc_status.go @@ -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)) diff --git a/command/status.go b/command/status.go index 9a77f9110..a8bc009cc 100644 --- a/command/status.go +++ b/command/status.go @@ -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))) } diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 01f53a041..01a962843 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -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