mirror of
https://github.com/hibiken/asynq.git
synced 2024-12-25 07:12:17 +08:00
Include each queue counts in stats command output
This commit is contained in:
parent
89843ac565
commit
2ff847d520
@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Changed
|
||||
|
||||
- [CLI] `asynqmon stats` now shows the total of all enqueued tasks under "Enqueued"
|
||||
- [CLI] `asynqmon stats` now shows each queue's task count
|
||||
- Task type is now immutable (i.e., Payload is read-only)
|
||||
|
||||
## [0.1.0] - 2020-01-04
|
||||
|
@ -7,6 +7,8 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
|
||||
@ -61,8 +63,12 @@ func stats(cmd *cobra.Command, args []string) {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println("STATES")
|
||||
printStates(stats)
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("QUEUES")
|
||||
printQueues(stats)
|
||||
printQueues(stats.Queues)
|
||||
fmt.Println()
|
||||
|
||||
fmt.Printf("STATS FOR %s UTC\n", stats.Timestamp.UTC().Format("2006-01-02"))
|
||||
@ -74,7 +80,7 @@ func stats(cmd *cobra.Command, args []string) {
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
func printQueues(s *rdb.Stats) {
|
||||
func printStates(s *rdb.Stats) {
|
||||
format := strings.Repeat("%v\t", 5) + "\n"
|
||||
tw := new(tabwriter.Writer).Init(os.Stdout, 0, 8, 2, ' ', 0)
|
||||
fmt.Fprintf(tw, format, "InProgress", "Enqueued", "Scheduled", "Retry", "Dead")
|
||||
@ -83,6 +89,24 @@ func printQueues(s *rdb.Stats) {
|
||||
tw.Flush()
|
||||
}
|
||||
|
||||
func printQueues(queues map[string]int) {
|
||||
var qnames, seps, counts []string
|
||||
for q := range queues {
|
||||
qnames = append(qnames, strings.Title(q))
|
||||
}
|
||||
sort.Strings(qnames) // sort for stable order
|
||||
for _, q := range qnames {
|
||||
seps = append(seps, strings.Repeat("-", len(q)))
|
||||
counts = append(counts, strconv.Itoa(queues[strings.ToLower(q)]))
|
||||
}
|
||||
format := strings.Repeat("%v\t", len(qnames)) + "\n"
|
||||
tw := new(tabwriter.Writer).Init(os.Stdout, 0, 8, 2, ' ', 0)
|
||||
fmt.Fprintf(tw, format, toInterfaceSlice(qnames)...)
|
||||
fmt.Fprintf(tw, format, toInterfaceSlice(seps)...)
|
||||
fmt.Fprintf(tw, format, toInterfaceSlice(counts)...)
|
||||
tw.Flush()
|
||||
}
|
||||
|
||||
func printStats(s *rdb.Stats) {
|
||||
format := strings.Repeat("%v\t", 3) + "\n"
|
||||
tw := new(tabwriter.Writer).Init(os.Stdout, 0, 8, 2, ' ', 0)
|
||||
@ -112,3 +136,11 @@ func printInfo(info map[string]string) {
|
||||
)
|
||||
tw.Flush()
|
||||
}
|
||||
|
||||
func toInterfaceSlice(strs []string) []interface{} {
|
||||
var res []interface{}
|
||||
for _, s := range strs {
|
||||
res = append(res, s)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user