Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Resolves #205 Updated pulsectl task to truncate count values
Browse files Browse the repository at this point in the history
  • Loading branch information
tiffanyfay committed Nov 5, 2015
1 parent 076c559 commit 4ae783b
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions cmd/pulsectl/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"os/signal"
"path/filepath"
"sort"
"strconv"
"strings"
"syscall"
"text/tabwriter"
Expand All @@ -47,6 +48,39 @@ var (
unionParseFormat = timeParseFormat + " " + dateParseFormat
)

const (
K = 1000
M = 1000 * K
G = 1000 * M
T = 1000 * G
P = 1000 * T
)

func trunc(n int) string {
var u string

switch {
case n >= P:
u = "P"
n /= P
case n >= T:
u = "T"
n /= T
case n >= G:
u = "G"
n /= G
case n >= M:
u = "M"
n /= M
case n >= K:
u = "K"
n /= K
default:
return strconv.Itoa(n)
}
return strconv.Itoa(n) + u
}

type task struct {
Version int
Schedule *client.Schedule
Expand Down Expand Up @@ -287,9 +321,9 @@ func listTask(ctx *cli.Context) {
task.ID,
task.Name,
task.State,
task.HitCount,
task.MissCount,
task.FailedCount,
trunc(task.HitCount),
trunc(task.MissCount),
trunc(task.FailedCount),
task.CreationTime().Format(unionParseFormat),
task.LastFailureMessage,
)
Expand Down

0 comments on commit 4ae783b

Please sign in to comment.