mirror of
https://github.com/hibiken/asynq.git
synced 2024-09-20 19:06:46 +08:00
42 lines
863 B
Go
42 lines
863 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"flag"
|
||
|
"fmt"
|
||
|
"log"
|
||
|
"os"
|
||
|
"strings"
|
||
|
"text/tabwriter"
|
||
|
"time"
|
||
|
|
||
|
"github.com/hibiken/asynq"
|
||
|
)
|
||
|
|
||
|
var pollInterval = flag.Duration("interval", 3*time.Second, "polling interval")
|
||
|
|
||
|
func main() {
|
||
|
inspector := asynq.NewInspector(&asynq.RedisConfig{
|
||
|
Addr: "localhost:6379",
|
||
|
DB: 2,
|
||
|
})
|
||
|
|
||
|
for {
|
||
|
stats, err := inspector.CurrentStats()
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
printStats(stats)
|
||
|
fmt.Println()
|
||
|
time.Sleep(*pollInterval)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func printStats(s *asynq.Stats) {
|
||
|
format := strings.Repeat("%v\t", 5) + "\n"
|
||
|
tw := new(tabwriter.Writer).Init(os.Stdout, 0, 8, 2, ' ', 0)
|
||
|
fmt.Fprintf(tw, format, "Enqueued", "InProgress", "Scheduled", "Retry", "Dead")
|
||
|
fmt.Fprintf(tw, format, "--------", "----------", "---------", "-----", "----")
|
||
|
fmt.Fprintf(tw, format, s.Queued, s.InProgress, s.Scheduled, s.Retry, s.Dead)
|
||
|
tw.Flush()
|
||
|
}
|