2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-11-10 11:31:58 +08:00

Minor improvement

This commit is contained in:
Ken Hibino 2019-12-09 06:22:08 -08:00
parent 4179c72c05
commit 8932ca41b3
6 changed files with 27 additions and 20 deletions

View File

@ -32,10 +32,10 @@ type RedisConfig struct {
DB int DB int
} }
func newRedisClient(config *RedisConfig) *redis.Client { func newRedisClient(cfg *RedisConfig) *redis.Client {
return redis.NewClient(&redis.Options{ return redis.NewClient(&redis.Options{
Addr: config.Addr, Addr: cfg.Addr,
Password: config.Password, Password: cfg.Password,
DB: config.DB, DB: cfg.DB,
}) })
} }

View File

@ -33,8 +33,8 @@ type Background struct {
// NewBackground returns a new Background with the specified number of workers // NewBackground returns a new Background with the specified number of workers
// given a redis configuration . // given a redis configuration .
func NewBackground(numWorkers int, config *RedisConfig) *Background { func NewBackground(numWorkers int, cfg *RedisConfig) *Background {
r := rdb.NewRDB(newRedisClient(config)) r := rdb.NewRDB(newRedisClient(cfg))
poller := newPoller(r, 5*time.Second) poller := newPoller(r, 5*time.Second)
processor := newProcessor(r, numWorkers, nil) processor := newProcessor(r, numWorkers, nil)
return &Background{ return &Background{

View File

@ -18,8 +18,8 @@ type Client struct {
} }
// NewClient and returns a new Client given a redis configuration. // NewClient and returns a new Client given a redis configuration.
func NewClient(config *RedisConfig) *Client { func NewClient(cfg *RedisConfig) *Client {
r := rdb.NewRDB(newRedisClient(config)) r := rdb.NewRDB(newRedisClient(cfg))
return &Client{r} return &Client{r}
} }

View File

@ -2,7 +2,7 @@ package cmd
import ( import (
"fmt" "fmt"
"log" "os"
"github.com/go-redis/redis/v7" "github.com/go-redis/redis/v7"
"github.com/hibiken/asynq/internal/rdb" "github.com/hibiken/asynq/internal/rdb"
@ -42,7 +42,8 @@ func init() {
func enq(cmd *cobra.Command, args []string) { func enq(cmd *cobra.Command, args []string) {
id, score, qtype, err := parseQueryID(args[0]) id, score, qtype, err := parseQueryID(args[0])
if err != nil { if err != nil {
log.Fatalln(err) fmt.Println(err)
os.Exit(1)
} }
r := rdb.NewRDB(redis.NewClient(&redis.Options{ r := rdb.NewRDB(redis.NewClient(&redis.Options{
Addr: uri, Addr: uri,
@ -56,10 +57,12 @@ func enq(cmd *cobra.Command, args []string) {
case "d": case "d":
err = r.Rescue(id.String(), float64(score)) err = r.Rescue(id.String(), float64(score))
default: default:
log.Fatalln("invalid argument") fmt.Println("invalid argument")
os.Exit(1)
} }
if err != nil { if err != nil {
log.Fatalln(err) fmt.Println(err)
os.Exit(1)
} }
fmt.Printf("Successfully enqueued %v\n", args[0]) fmt.Printf("Successfully enqueued %v\n", args[0])
} }

View File

@ -3,7 +3,6 @@ package cmd
import ( import (
"fmt" "fmt"
"io" "io"
"log"
"os" "os"
"strconv" "strconv"
"strings" "strings"
@ -105,7 +104,8 @@ func parseQueryID(queryID string) (id uuid.UUID, score float64, qtype string, er
func listEnqueued(r *rdb.RDB) { func listEnqueued(r *rdb.RDB) {
tasks, err := r.ListEnqueued() tasks, err := r.ListEnqueued()
if err != nil { if err != nil {
log.Fatalln(err) fmt.Println(err)
os.Exit(1)
} }
if len(tasks) == 0 { if len(tasks) == 0 {
fmt.Println("No enqueued tasks") fmt.Println("No enqueued tasks")
@ -123,7 +123,8 @@ func listEnqueued(r *rdb.RDB) {
func listInProgress(r *rdb.RDB) { func listInProgress(r *rdb.RDB) {
tasks, err := r.ListInProgress() tasks, err := r.ListInProgress()
if err != nil { if err != nil {
log.Fatalln(err) fmt.Println(err)
os.Exit(1)
} }
if len(tasks) == 0 { if len(tasks) == 0 {
fmt.Println("No in-progress tasks") fmt.Println("No in-progress tasks")
@ -141,7 +142,8 @@ func listInProgress(r *rdb.RDB) {
func listScheduled(r *rdb.RDB) { func listScheduled(r *rdb.RDB) {
tasks, err := r.ListScheduled() tasks, err := r.ListScheduled()
if err != nil { if err != nil {
log.Fatalln(err) fmt.Println(err)
os.Exit(1)
} }
if len(tasks) == 0 { if len(tasks) == 0 {
fmt.Println("No scheduled tasks") fmt.Println("No scheduled tasks")
@ -160,7 +162,8 @@ func listScheduled(r *rdb.RDB) {
func listRetry(r *rdb.RDB) { func listRetry(r *rdb.RDB) {
tasks, err := r.ListRetry() tasks, err := r.ListRetry()
if err != nil { if err != nil {
log.Fatalln(err) fmt.Println(err)
os.Exit(1)
} }
if len(tasks) == 0 { if len(tasks) == 0 {
fmt.Println("No retry tasks") fmt.Println("No retry tasks")
@ -179,7 +182,8 @@ func listRetry(r *rdb.RDB) {
func listDead(r *rdb.RDB) { func listDead(r *rdb.RDB) {
tasks, err := r.ListDead() tasks, err := r.ListDead()
if err != nil { if err != nil {
log.Fatalln(err) fmt.Println(err)
os.Exit(1)
} }
if len(tasks) == 0 { if len(tasks) == 0 {
fmt.Println("No dead tasks") fmt.Println("No dead tasks")

View File

@ -2,7 +2,6 @@ package cmd
import ( import (
"fmt" "fmt"
"log"
"os" "os"
"strings" "strings"
"text/tabwriter" "text/tabwriter"
@ -49,7 +48,8 @@ func stats(cmd *cobra.Command, args []string) {
stats, err := r.CurrentStats() stats, err := r.CurrentStats()
if err != nil { if err != nil {
log.Fatal(err) fmt.Println(err)
os.Exit(1)
} }
printStats(stats) printStats(stats)
fmt.Println() fmt.Println()