mirror of
https://github.com/hibiken/asynq.git
synced 2024-12-24 23:02:18 +08:00
Add pause and unpause command to CLI
This commit is contained in:
parent
363cfedb49
commit
d6a5c84dc6
47
tools/asynq/cmd/pause.go
Normal file
47
tools/asynq/cmd/pause.go
Normal file
@ -0,0 +1,47 @@
|
||||
// Copyright 2020 Kentaro Hibino. All rights reserved.
|
||||
// Use of this source code is governed by a MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/go-redis/redis/v7"
|
||||
"github.com/hibiken/asynq/internal/rdb"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// pauseCmd represents the pause command
|
||||
var pauseCmd = &cobra.Command{
|
||||
Use: "pause [queue name]",
|
||||
Short: "Pauses the specified queue",
|
||||
Long: `Pause (asynq pause) will pause the specified queue.
|
||||
Asynq servers will not process tasks from paused queues.
|
||||
Use the "unpause" command to resume a paused queue.
|
||||
|
||||
Example: asynq pause default -> Pause the "default" queue`,
|
||||
Args: cobra.ExactValidArgs(1),
|
||||
Run: pause,
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(pauseCmd)
|
||||
}
|
||||
|
||||
func pause(cmd *cobra.Command, args []string) {
|
||||
c := redis.NewClient(&redis.Options{
|
||||
Addr: viper.GetString("uri"),
|
||||
DB: viper.GetInt("db"),
|
||||
Password: viper.GetString("password"),
|
||||
})
|
||||
r := rdb.NewRDB(c)
|
||||
err := r.Pause(args[0])
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("Successfully paused queue %q\n", args[0])
|
||||
}
|
46
tools/asynq/cmd/unpause.go
Normal file
46
tools/asynq/cmd/unpause.go
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright 2020 Kentaro Hibino. All rights reserved.
|
||||
// Use of this source code is governed by a MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/go-redis/redis/v7"
|
||||
"github.com/hibiken/asynq/internal/rdb"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// unpauseCmd represents the unpause command
|
||||
var unpauseCmd = &cobra.Command{
|
||||
Use: "unpause [queue name]",
|
||||
Short: "Unpauses the specified queue",
|
||||
Long: `Unpause (asynq unpause) will unpause the specified queue.
|
||||
Asynq servers will process tasks from unpaused/resumed queues.
|
||||
|
||||
Example: asynq unpause default -> Resume the "default" queue`,
|
||||
Args: cobra.ExactValidArgs(1),
|
||||
Run: unpause,
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(unpauseCmd)
|
||||
}
|
||||
|
||||
func unpause(cmd *cobra.Command, args []string) {
|
||||
c := redis.NewClient(&redis.Options{
|
||||
Addr: viper.GetString("uri"),
|
||||
DB: viper.GetInt("db"),
|
||||
Password: viper.GetString("password"),
|
||||
})
|
||||
r := rdb.NewRDB(c)
|
||||
err := r.Unpause(args[0])
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("Successfully resumed queue %q\n", args[0])
|
||||
}
|
Loading…
Reference in New Issue
Block a user