diff --git a/cmd/asynqmon/main.go b/cmd/asynqmon/main.go new file mode 100644 index 0000000..72c826d --- /dev/null +++ b/cmd/asynqmon/main.go @@ -0,0 +1,41 @@ +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() +} diff --git a/inspector.go b/inspector.go index fe4dbb7..39697cc 100644 --- a/inspector.go +++ b/inspector.go @@ -6,9 +6,9 @@ type Inspector struct { } // NewInspector returns a new Inspector instance. -func NewInspector(opt *RedisOpt) *Inspector { +func NewInspector(config *RedisConfig) *Inspector { return &Inspector{ - rdb: newRDB(opt), + rdb: newRDB(config), } }