mirror of
https://github.com/hibiken/asynq.git
synced 2025-08-24 14:48:40 +08:00
Add enqall command to asynqmon CLI
This commit is contained in:
@@ -11,9 +11,9 @@ import (
|
||||
|
||||
// enqCmd represents the enq command
|
||||
var enqCmd = &cobra.Command{
|
||||
Use: "enq",
|
||||
Use: "enq [task id]",
|
||||
Short: "Enqueues a task given an identifier",
|
||||
Long: `The enq command enqueues a task given an identifier.
|
||||
Long: `Enq (asynqmon enq) will enqueue a task given an identifier.
|
||||
|
||||
The command takes one argument which specifies the task to enqueue.
|
||||
The task should be in either scheduled, retry or dead queue.
|
||||
|
69
tools/asynqmon/cmd/enqall.go
Normal file
69
tools/asynqmon/cmd/enqall.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/go-redis/redis/v7"
|
||||
"github.com/hibiken/asynq/internal/rdb"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var enqallValidArgs = []string{"scheduled", "retry", "dead"}
|
||||
|
||||
// enqallCmd represents the enqall command
|
||||
var enqallCmd = &cobra.Command{
|
||||
Use: "enqall [queue name]",
|
||||
Short: "Enqueues all tasks from the specified queue",
|
||||
Long: `Enqall (asynqmon enqall) will enqueue all tasks from the specified queue.
|
||||
|
||||
The argument should be one of "scheduled", "retry", or "dead".
|
||||
|
||||
The tasks enqueued by this command will be processed as soon as it
|
||||
gets dequeued by a processor.
|
||||
|
||||
Example: asynqmon enqall dead -> Enqueues all tasks from the dead queue`,
|
||||
ValidArgs: enqallValidArgs,
|
||||
Args: cobra.ExactValidArgs(1),
|
||||
Run: enqall,
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(enqallCmd)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
||||
// Cobra supports Persistent Flags which will work for this command
|
||||
// and all subcommands, e.g.:
|
||||
// enqallCmd.PersistentFlags().String("foo", "", "A help for foo")
|
||||
|
||||
// Cobra supports local flags which will only run when this command
|
||||
// is called directly, e.g.:
|
||||
// enqallCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||
}
|
||||
|
||||
func enqall(cmd *cobra.Command, args []string) {
|
||||
c := redis.NewClient(&redis.Options{
|
||||
Addr: uri,
|
||||
DB: db,
|
||||
})
|
||||
r := rdb.NewRDB(c)
|
||||
var n int64
|
||||
var err error
|
||||
switch args[0] {
|
||||
case "scheduled":
|
||||
n, err = r.EnqueueAllScheduledTasks()
|
||||
case "retry":
|
||||
n, err = r.EnqueueAllRetryTasks()
|
||||
case "dead":
|
||||
n, err = r.EnqueueAllDeadTasks()
|
||||
default:
|
||||
fmt.Printf("error: `asynqmon enqall <queue>` only accepts %v as the argument.\n", enqallValidArgs)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("Enqueued %d tasks from %q queue\n", n, args[0])
|
||||
}
|
@@ -15,20 +15,20 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var validArgs = []string{"enqueued", "inprogress", "scheduled", "retry", "dead"}
|
||||
var lsValidArgs = []string{"enqueued", "inprogress", "scheduled", "retry", "dead"}
|
||||
|
||||
// lsCmd represents the ls command
|
||||
var lsCmd = &cobra.Command{
|
||||
Use: "ls",
|
||||
Use: "ls [queue name]",
|
||||
Short: "Lists queue contents",
|
||||
Long: `The ls command lists all tasks from the specified queue in a table format.
|
||||
Long: `Ls (asynqmon ls) will list all tasks from the specified queue in a table format.
|
||||
|
||||
The command takes one argument which specifies the queue to inspect. The value
|
||||
of the argument should be one of "enqueued", "inprogress", "scheduled",
|
||||
"retry", or "dead".
|
||||
|
||||
Example: asynqmon ls dead`,
|
||||
ValidArgs: validArgs,
|
||||
ValidArgs: lsValidArgs,
|
||||
Args: cobra.ExactValidArgs(1),
|
||||
Run: ls,
|
||||
}
|
||||
@@ -65,8 +65,8 @@ func ls(cmd *cobra.Command, args []string) {
|
||||
case "dead":
|
||||
listDead(r)
|
||||
default:
|
||||
fmt.Printf("error: `asynqmon ls <queue>` only accepts %v as the argument.\n", validArgs)
|
||||
return
|
||||
fmt.Printf("error: `asynqmon ls <queue>` only accepts %v as the argument.\n", lsValidArgs)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -50,6 +50,7 @@ func init() {
|
||||
}
|
||||
|
||||
// initConfig reads in config file and ENV variables if set.
|
||||
// TODO(hibiken): Remove this if not necessary.
|
||||
func initConfig() {
|
||||
if cfgFile != "" {
|
||||
// Use config file from the flag.
|
||||
|
@@ -15,7 +15,7 @@ import (
|
||||
var statsCmd = &cobra.Command{
|
||||
Use: "stats",
|
||||
Short: "Shows current state of the queues",
|
||||
Long: `The stats command shows the number of tasks in each queue at that instant.
|
||||
Long: `Stats (aysnqmon stats) will show the number of tasks in each queue at that instant.
|
||||
|
||||
To monitor the queues continuously, it's recommended that you run this
|
||||
command in conjunction with the watch command.
|
||||
|
Reference in New Issue
Block a user