mirror of
https://github.com/hibiken/asynq.git
synced 2025-02-23 04:10:17 +08:00
[ci skip] Allow config file to set default values for flags
This commit is contained in:
parent
d37f2a09ab
commit
959c9fd01a
5
.gitignore
vendored
5
.gitignore
vendored
@ -15,4 +15,7 @@
|
|||||||
/examples
|
/examples
|
||||||
|
|
||||||
# Ignore command binary
|
# Ignore command binary
|
||||||
/tools/asynqmon/asynqmon
|
/tools/asynqmon/asynqmon
|
||||||
|
|
||||||
|
# Ignore asynqmon config file
|
||||||
|
.asynqmon.*
|
@ -2,6 +2,20 @@
|
|||||||
|
|
||||||
Asynqmon is a CLI tool to monitor the queues managed by `asynq` package.
|
Asynqmon is a CLI tool to monitor the queues managed by `asynq` package.
|
||||||
|
|
||||||
|
## Table of Contents
|
||||||
|
|
||||||
|
- [Installation](#installation)
|
||||||
|
- [Quick Start](#quick-start)
|
||||||
|
- [Stats](#stats)
|
||||||
|
- [History](#history)
|
||||||
|
- [List](#list)
|
||||||
|
- [Enqueue](#enqueue)
|
||||||
|
- [Delete](#delete)
|
||||||
|
- [Kill](#kill)
|
||||||
|
- [Config File](#config-file)
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
In order to use the tool, compile it using the following command:
|
In order to use the tool, compile it using the following command:
|
||||||
|
|
||||||
go get github.com/hibiken/asynq/tools/asynqmon
|
go get github.com/hibiken/asynq/tools/asynqmon
|
||||||
@ -29,3 +43,41 @@ Example:
|
|||||||
This will run `asynqmon stats` command every 3 seconds.
|
This will run `asynqmon stats` command every 3 seconds.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
### History
|
||||||
|
|
||||||
|
TODO: Add discription
|
||||||
|
|
||||||
|
### List
|
||||||
|
|
||||||
|
TODO: Add discription
|
||||||
|
|
||||||
|
### Enqueue
|
||||||
|
|
||||||
|
TODO: Add discription
|
||||||
|
|
||||||
|
### Delete
|
||||||
|
|
||||||
|
TODO: Add discription
|
||||||
|
|
||||||
|
### Kill
|
||||||
|
|
||||||
|
TODO: Add discription
|
||||||
|
|
||||||
|
## Config File
|
||||||
|
|
||||||
|
You can use a config file to set default values for flags.
|
||||||
|
This is useful, for example when you have to connect to a remote redis server.
|
||||||
|
|
||||||
|
By default, `asynqmon` will try to read config file located in
|
||||||
|
`$HOME/.asynqmon.(yml|json)`. You can specify the file location via `--config` flag.
|
||||||
|
|
||||||
|
Config file example:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
uri: 127.0.0.1:6379
|
||||||
|
db: 2
|
||||||
|
password: mypassword
|
||||||
|
```
|
||||||
|
|
||||||
|
This will set the default values for `--uri`, `--db`, and `--password` flags.
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/go-redis/redis/v7"
|
"github.com/go-redis/redis/v7"
|
||||||
"github.com/hibiken/asynq/internal/rdb"
|
"github.com/hibiken/asynq/internal/rdb"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
// delCmd represents the del command
|
// delCmd represents the del command
|
||||||
@ -49,8 +50,9 @@ func del(cmd *cobra.Command, args []string) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
r := rdb.NewRDB(redis.NewClient(&redis.Options{
|
r := rdb.NewRDB(redis.NewClient(&redis.Options{
|
||||||
Addr: uri,
|
Addr: viper.GetString("uri"),
|
||||||
DB: db,
|
DB: viper.GetInt("db"),
|
||||||
|
Password: viper.GetString("password"),
|
||||||
}))
|
}))
|
||||||
switch qtype {
|
switch qtype {
|
||||||
case "s":
|
case "s":
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/go-redis/redis/v7"
|
"github.com/go-redis/redis/v7"
|
||||||
"github.com/hibiken/asynq/internal/rdb"
|
"github.com/hibiken/asynq/internal/rdb"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var delallValidArgs = []string{"scheduled", "retry", "dead"}
|
var delallValidArgs = []string{"scheduled", "retry", "dead"}
|
||||||
@ -45,8 +46,9 @@ func init() {
|
|||||||
|
|
||||||
func delall(cmd *cobra.Command, args []string) {
|
func delall(cmd *cobra.Command, args []string) {
|
||||||
c := redis.NewClient(&redis.Options{
|
c := redis.NewClient(&redis.Options{
|
||||||
Addr: uri,
|
Addr: viper.GetString("uri"),
|
||||||
DB: db,
|
DB: viper.GetInt("db"),
|
||||||
|
Password: viper.GetString("password"),
|
||||||
})
|
})
|
||||||
r := rdb.NewRDB(c)
|
r := rdb.NewRDB(c)
|
||||||
var err error
|
var err error
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/go-redis/redis/v7"
|
"github.com/go-redis/redis/v7"
|
||||||
"github.com/hibiken/asynq/internal/rdb"
|
"github.com/hibiken/asynq/internal/rdb"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
// enqCmd represents the enq command
|
// enqCmd represents the enq command
|
||||||
@ -52,8 +53,9 @@ func enq(cmd *cobra.Command, args []string) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
r := rdb.NewRDB(redis.NewClient(&redis.Options{
|
r := rdb.NewRDB(redis.NewClient(&redis.Options{
|
||||||
Addr: uri,
|
Addr: viper.GetString("uri"),
|
||||||
DB: db,
|
DB: viper.GetInt("db"),
|
||||||
|
Password: viper.GetString("password"),
|
||||||
}))
|
}))
|
||||||
switch qtype {
|
switch qtype {
|
||||||
case "s":
|
case "s":
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/go-redis/redis/v7"
|
"github.com/go-redis/redis/v7"
|
||||||
"github.com/hibiken/asynq/internal/rdb"
|
"github.com/hibiken/asynq/internal/rdb"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var enqallValidArgs = []string{"scheduled", "retry", "dead"}
|
var enqallValidArgs = []string{"scheduled", "retry", "dead"}
|
||||||
@ -48,8 +49,9 @@ func init() {
|
|||||||
|
|
||||||
func enqall(cmd *cobra.Command, args []string) {
|
func enqall(cmd *cobra.Command, args []string) {
|
||||||
c := redis.NewClient(&redis.Options{
|
c := redis.NewClient(&redis.Options{
|
||||||
Addr: uri,
|
Addr: viper.GetString("uri"),
|
||||||
DB: db,
|
DB: viper.GetInt("db"),
|
||||||
|
Password: viper.GetString("password"),
|
||||||
})
|
})
|
||||||
r := rdb.NewRDB(c)
|
r := rdb.NewRDB(c)
|
||||||
var n int64
|
var n int64
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/go-redis/redis/v7"
|
"github.com/go-redis/redis/v7"
|
||||||
"github.com/hibiken/asynq/internal/rdb"
|
"github.com/hibiken/asynq/internal/rdb"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
// historyCmd represents the history command
|
// historyCmd represents the history command
|
||||||
@ -55,8 +56,9 @@ Usage: asynqmon history [num of days]
|
|||||||
|
|
||||||
}
|
}
|
||||||
c := redis.NewClient(&redis.Options{
|
c := redis.NewClient(&redis.Options{
|
||||||
Addr: uri,
|
Addr: viper.GetString("uri"),
|
||||||
DB: db,
|
DB: viper.GetInt("db"),
|
||||||
|
Password: viper.GetString("password"),
|
||||||
})
|
})
|
||||||
r := rdb.NewRDB(c)
|
r := rdb.NewRDB(c)
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/go-redis/redis/v7"
|
"github.com/go-redis/redis/v7"
|
||||||
"github.com/hibiken/asynq/internal/rdb"
|
"github.com/hibiken/asynq/internal/rdb"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
// killCmd represents the kill command
|
// killCmd represents the kill command
|
||||||
@ -49,8 +50,9 @@ func kill(cmd *cobra.Command, args []string) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
r := rdb.NewRDB(redis.NewClient(&redis.Options{
|
r := rdb.NewRDB(redis.NewClient(&redis.Options{
|
||||||
Addr: uri,
|
Addr: viper.GetString("uri"),
|
||||||
DB: db,
|
DB: viper.GetInt("db"),
|
||||||
|
Password: viper.GetString("password"),
|
||||||
}))
|
}))
|
||||||
switch qtype {
|
switch qtype {
|
||||||
case "s":
|
case "s":
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/go-redis/redis/v7"
|
"github.com/go-redis/redis/v7"
|
||||||
"github.com/hibiken/asynq/internal/rdb"
|
"github.com/hibiken/asynq/internal/rdb"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var killallValidArgs = []string{"scheduled", "retry"}
|
var killallValidArgs = []string{"scheduled", "retry"}
|
||||||
@ -45,8 +46,9 @@ func init() {
|
|||||||
|
|
||||||
func killall(cmd *cobra.Command, args []string) {
|
func killall(cmd *cobra.Command, args []string) {
|
||||||
c := redis.NewClient(&redis.Options{
|
c := redis.NewClient(&redis.Options{
|
||||||
Addr: uri,
|
Addr: viper.GetString("uri"),
|
||||||
DB: db,
|
DB: viper.GetInt("db"),
|
||||||
|
Password: viper.GetString("password"),
|
||||||
})
|
})
|
||||||
r := rdb.NewRDB(c)
|
r := rdb.NewRDB(c)
|
||||||
var n int64
|
var n int64
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/hibiken/asynq/internal/rdb"
|
"github.com/hibiken/asynq/internal/rdb"
|
||||||
"github.com/rs/xid"
|
"github.com/rs/xid"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var lsValidArgs = []string{"enqueued", "inprogress", "scheduled", "retry", "dead"}
|
var lsValidArgs = []string{"enqueued", "inprogress", "scheduled", "retry", "dead"}
|
||||||
@ -58,8 +59,9 @@ func init() {
|
|||||||
|
|
||||||
func ls(cmd *cobra.Command, args []string) {
|
func ls(cmd *cobra.Command, args []string) {
|
||||||
c := redis.NewClient(&redis.Options{
|
c := redis.NewClient(&redis.Options{
|
||||||
Addr: uri,
|
Addr: viper.GetString("uri"),
|
||||||
DB: db,
|
DB: viper.GetInt("db"),
|
||||||
|
Password: viper.GetString("password"),
|
||||||
})
|
})
|
||||||
r := rdb.NewRDB(c)
|
r := rdb.NewRDB(c)
|
||||||
parts := strings.Split(args[0], ":")
|
parts := strings.Split(args[0], ":")
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/go-redis/redis/v7"
|
"github.com/go-redis/redis/v7"
|
||||||
"github.com/hibiken/asynq/internal/rdb"
|
"github.com/hibiken/asynq/internal/rdb"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
// rmqCmd represents the rmq command
|
// rmqCmd represents the rmq command
|
||||||
@ -35,8 +36,9 @@ func init() {
|
|||||||
|
|
||||||
func rmq(cmd *cobra.Command, args []string) {
|
func rmq(cmd *cobra.Command, args []string) {
|
||||||
c := redis.NewClient(&redis.Options{
|
c := redis.NewClient(&redis.Options{
|
||||||
Addr: uri,
|
Addr: viper.GetString("uri"),
|
||||||
DB: db,
|
DB: viper.GetInt("db"),
|
||||||
|
Password: viper.GetString("password"),
|
||||||
})
|
})
|
||||||
r := rdb.NewRDB(c)
|
r := rdb.NewRDB(c)
|
||||||
err := r.RemoveQueue(args[0], rmqForce)
|
err := r.RemoveQueue(args[0], rmqForce)
|
||||||
|
@ -6,9 +6,10 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
homedir "github.com/mitchellh/go-homedir"
|
homedir "github.com/mitchellh/go-homedir"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
@ -18,6 +19,7 @@ var cfgFile string
|
|||||||
// Flags
|
// Flags
|
||||||
var uri string
|
var uri string
|
||||||
var db int
|
var db int
|
||||||
|
var password string
|
||||||
|
|
||||||
// rootCmd represents the base command when called without any subcommands
|
// rootCmd represents the base command when called without any subcommands
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
@ -31,9 +33,6 @@ Monitoring commands such as "stats" and "ls" can be used in conjunction with the
|
|||||||
"watch" command to continuously run the command at a certain interval.
|
"watch" command to continuously run the command at a certain interval.
|
||||||
|
|
||||||
Example: watch -n 5 asynqmon stats`,
|
Example: watch -n 5 asynqmon stats`,
|
||||||
// Uncomment the following line if your bare application
|
|
||||||
// has an action associated with it:
|
|
||||||
// Run: func(cmd *cobra.Command, args []string) { },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||||
@ -48,13 +47,16 @@ func Execute() {
|
|||||||
func init() {
|
func init() {
|
||||||
cobra.OnInitialize(initConfig)
|
cobra.OnInitialize(initConfig)
|
||||||
|
|
||||||
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.asynqmon.yaml)")
|
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file to set flag defaut values (default is $HOME/.asynqmon.yaml)")
|
||||||
rootCmd.PersistentFlags().StringVarP(&uri, "uri", "u", "127.0.0.1:6379", "Redis server URI")
|
rootCmd.PersistentFlags().StringVarP(&uri, "uri", "u", "127.0.0.1:6379", "redis server URI")
|
||||||
rootCmd.PersistentFlags().IntVarP(&db, "db", "n", 0, "Redis database number (default is 0)")
|
rootCmd.PersistentFlags().IntVarP(&db, "db", "n", 0, "redis database number (default is 0)")
|
||||||
|
rootCmd.PersistentFlags().StringVarP(&password, "password", "p", "", "password to use when connecting to redis server")
|
||||||
|
viper.BindPFlag("uri", rootCmd.PersistentFlags().Lookup("uri"))
|
||||||
|
viper.BindPFlag("db", rootCmd.PersistentFlags().Lookup("db"))
|
||||||
|
viper.BindPFlag("password", rootCmd.PersistentFlags().Lookup("password"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// initConfig reads in config file and ENV variables if set.
|
// initConfig reads in config file and ENV variables if set.
|
||||||
// TODO(hibiken): Remove this if not necessary.
|
|
||||||
func initConfig() {
|
func initConfig() {
|
||||||
if cfgFile != "" {
|
if cfgFile != "" {
|
||||||
// Use config file from the flag.
|
// Use config file from the flag.
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/go-redis/redis/v7"
|
"github.com/go-redis/redis/v7"
|
||||||
"github.com/hibiken/asynq/internal/rdb"
|
"github.com/hibiken/asynq/internal/rdb"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
// statsCmd represents the stats command
|
// statsCmd represents the stats command
|
||||||
@ -48,8 +49,9 @@ func init() {
|
|||||||
|
|
||||||
func stats(cmd *cobra.Command, args []string) {
|
func stats(cmd *cobra.Command, args []string) {
|
||||||
c := redis.NewClient(&redis.Options{
|
c := redis.NewClient(&redis.Options{
|
||||||
Addr: uri,
|
Addr: viper.GetString("uri"),
|
||||||
DB: db,
|
DB: viper.GetInt("db"),
|
||||||
|
Password: viper.GetString("password"),
|
||||||
})
|
})
|
||||||
r := rdb.NewRDB(c)
|
r := rdb.NewRDB(c)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user