2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-09-20 11:05: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
}
func newRedisClient(config *RedisConfig) *redis.Client {
func newRedisClient(cfg *RedisConfig) *redis.Client {
return redis.NewClient(&redis.Options{
Addr: config.Addr,
Password: config.Password,
DB: config.DB,
Addr: cfg.Addr,
Password: cfg.Password,
DB: cfg.DB,
})
}

View File

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

View File

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

View File

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

View File

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

View File

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