2
0
mirror of https://github.com/hibiken/asynq.git synced 2025-10-03 05:12:01 +08:00

(cli): Disallow refresh interval less than 1s

This commit is contained in:
Ken Hibino
2022-05-27 13:58:41 -07:00
parent 6058e369c3
commit 2f95ff0442

View File

@@ -5,6 +5,8 @@
package cmd package cmd
import ( import (
"fmt"
"os"
"time" "time"
"github.com/MakeNowJust/heredoc/v2" "github.com/MakeNowJust/heredoc/v2"
@@ -20,7 +22,7 @@ var (
func init() { func init() {
rootCmd.AddCommand(dashCmd) rootCmd.AddCommand(dashCmd)
dashCmd.Flags().DurationVar(&flagPollInterval, "refresh", 8*time.Second, "Interval between data refresh") dashCmd.Flags().DurationVar(&flagPollInterval, "refresh", 8*time.Second, "Interval between data refresh. Minimum value is 1s.")
// TODO: Remove this debug once we're done // TODO: Remove this debug once we're done
dashCmd.Flags().BoolVar(&flagDebug, "debug", false, "Print debug info") dashCmd.Flags().BoolVar(&flagDebug, "debug", false, "Print debug info")
dashCmd.Flags().BoolVar(&flagUseRealData, "realdata", true, "Use real data in redis") dashCmd.Flags().BoolVar(&flagUseRealData, "realdata", true, "Use real data in redis")
@@ -33,6 +35,10 @@ var dashCmd = &cobra.Command{
Displays dashboard.`), Displays dashboard.`),
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if flagPollInterval < 1*time.Second {
fmt.Println("error: --refresh cannot be less than 1s")
os.Exit(1)
}
dash.Run(dash.Options{ dash.Run(dash.Options{
DebugMode: flagDebug, DebugMode: flagDebug,
UseRealData: flagUseRealData, UseRealData: flagUseRealData,