Skip to content

Commit

Permalink
Adds modify time to job/alloc status CLI output, and pretty prints
Browse files Browse the repository at this point in the history
  • Loading branch information
preetapan committed Oct 26, 2017
1 parent 95d26c7 commit 3f0d46c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
6 changes: 5 additions & 1 deletion command/alloc_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ func (c *AllocStatusCommand) Run(args []string) int {
}

func formatAllocBasicInfo(alloc *api.Allocation, client *api.Client, uuidLength int, verbose bool) (string, error) {
formattedCreateTime := formatTimePretty(time.Unix(0, alloc.CreateTime), time.Now())
formattedModifyTime := formatTimePretty(time.Unix(0, alloc.ModifyTime), time.Now())

basic := []string{
fmt.Sprintf("ID|%s", limit(alloc.ID, uuidLength)),
fmt.Sprintf("Eval ID|%s", limit(alloc.EvalID, uuidLength)),
Expand All @@ -225,7 +228,8 @@ func formatAllocBasicInfo(alloc *api.Allocation, client *api.Client, uuidLength
fmt.Sprintf("Client Description|%s", alloc.ClientDescription),
fmt.Sprintf("Desired Status|%s", alloc.DesiredStatus),
fmt.Sprintf("Desired Description|%s", alloc.DesiredDescription),
fmt.Sprintf("Created At|%s", formatUnixNanoTime(alloc.CreateTime)),
fmt.Sprintf("Created|%s", formattedCreateTime),
fmt.Sprintf("Modified|%s", formattedModifyTime),
}

if alloc.DeploymentID != "" {
Expand Down
5 changes: 5 additions & 0 deletions command/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ func formatTimeDifference(first, second time.Time, d time.Duration) string {
return second.Truncate(d).Sub(first.Truncate(d)).String()
}

// formatTimePretty rounds off time difference to the nearest second for nicer display
func formatTimePretty(first, second time.Time) string {
return formatTimeDifference(first.Round(time.Second), second.Round(time.Second), time.Second) + " ago"
}

// getLocalNodeID returns the node ID of the local Nomad Client and an error if
// it couldn't be determined or the Agent is not running in Client mode.
func getLocalNodeID(client *api.Client) (string, error) {
Expand Down
16 changes: 10 additions & 6 deletions command/job_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,29 +406,33 @@ func formatAllocListStubs(stubs []*api.AllocationListStub, verbose bool, uuidLen

allocs := make([]string, len(stubs)+1)
if verbose {
allocs[0] = "ID|Eval ID|Node ID|Task Group|Version|Desired|Status|Created At"
allocs[0] = "ID|Eval ID|Node ID|Task Group|Version|Desired|Status|Created At|Modified At"
for i, alloc := range stubs {
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%s|%d|%s|%s|%s",
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%s|%d|%s|%s|%s|%s",
limit(alloc.ID, uuidLength),
limit(alloc.EvalID, uuidLength),
limit(alloc.NodeID, uuidLength),
alloc.TaskGroup,
alloc.JobVersion,
alloc.DesiredStatus,
alloc.ClientStatus,
formatUnixNanoTime(alloc.CreateTime))
formatUnixNanoTime(alloc.CreateTime),
formatUnixNanoTime(alloc.ModifyTime))
}
} else {
allocs[0] = "ID|Node ID|Task Group|Version|Desired|Status|Created At"
allocs[0] = "ID|Node ID|Task Group|Version|Desired|Status|Created|Modified"
for i, alloc := range stubs {
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%d|%s|%s|%s",
createTimePretty := formatTimePretty(time.Unix(0, alloc.CreateTime), time.Now())
modTimePretty := formatTimePretty(time.Unix(0, alloc.ModifyTime), time.Now())
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%d|%s|%s|%s|%s",
limit(alloc.ID, uuidLength),
limit(alloc.NodeID, uuidLength),
alloc.TaskGroup,
alloc.JobVersion,
alloc.DesiredStatus,
alloc.ClientStatus,
formatUnixNanoTime(alloc.CreateTime))
createTimePretty,
modTimePretty)
}
}

Expand Down

0 comments on commit 3f0d46c

Please sign in to comment.