2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-25 07:12:17 +08:00

Change asynqmon history command to take no arguments

This commit is contained in:
Ken Hibino 2020-01-19 15:04:52 -08:00
parent 959c9fd01a
commit 9e872a4cb4
2 changed files with 12 additions and 29 deletions

View File

@ -7,7 +7,6 @@ package cmd
import ( import (
"fmt" "fmt"
"os" "os"
"strconv"
"strings" "strings"
"text/tabwriter" "text/tabwriter"
@ -17,44 +16,28 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
var days int
// historyCmd represents the history command // historyCmd represents the history command
var historyCmd = &cobra.Command{ var historyCmd = &cobra.Command{
Use: "history [num of days]", Use: "history",
Short: "Shows historical aggregate data", Short: "Shows historical aggregate data",
Long: `History (asynqmon history) will show the number of processed tasks Long: `History (asynqmon history) will show the number of processed and failed tasks
as well as the error rate for the last n days. from the last x days.
Example: asynqmon history 7 -> Shows stats from the last 7 days`, By default, it will show the data from the last 10 days.
Args: cobra.ExactArgs(1),
Example: asynqmon history -x=30 -> Shows stats from the last 30 days`,
Args: cobra.NoArgs,
Run: history, Run: history,
} }
func init() { func init() {
rootCmd.AddCommand(historyCmd) rootCmd.AddCommand(historyCmd)
historyCmd.Flags().IntVarP(&days, "days", "x", 10, "show data from last x days")
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// historyCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// historyCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
} }
func history(cmd *cobra.Command, args []string) { func history(cmd *cobra.Command, args []string) {
n, err := strconv.Atoi(args[0])
if err != nil {
fmt.Printf(`Error: Invalid argument. Argument has to be an integer.
Usage: asynqmon history [num of days]
`)
os.Exit(1)
}
if err != nil {
}
c := redis.NewClient(&redis.Options{ c := redis.NewClient(&redis.Options{
Addr: viper.GetString("uri"), Addr: viper.GetString("uri"),
DB: viper.GetInt("db"), DB: viper.GetInt("db"),
@ -62,7 +45,7 @@ Usage: asynqmon history [num of days]
}) })
r := rdb.NewRDB(c) r := rdb.NewRDB(c)
stats, err := r.HistoricalStats(n) stats, err := r.HistoricalStats(days)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)

View File

@ -31,7 +31,7 @@ var rmqForce bool
func init() { func init() {
rootCmd.AddCommand(rmqCmd) rootCmd.AddCommand(rmqCmd)
rmqCmd.Flags().BoolVarP(&rmqForce, "force", "f", false, "Remove the queue regardless of its size") rmqCmd.Flags().BoolVarP(&rmqForce, "force", "f", false, "remove the queue regardless of its size")
} }
func rmq(cmd *cobra.Command, args []string) { func rmq(cmd *cobra.Command, args []string) {