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

Rename Workers to Launcher

This commit is contained in:
Ken Hibino 2019-11-19 06:19:22 -08:00
parent 4485b6e3a9
commit 89c54fb47d

View File

@ -102,8 +102,8 @@ func (c *Client) enqueue(msg *taskMessage, executeAt time.Time) error {
//-------------------- Workers -------------------- //-------------------- Workers --------------------
// Workers represents a pool of workers. // Launcher starts the manager and poller.
type Workers struct { type Launcher struct {
rdb *redis.Client rdb *redis.Client
// poolTokens is a counting semaphore to ensure the number of active workers // poolTokens is a counting semaphore to ensure the number of active workers
@ -116,8 +116,8 @@ type Workers struct {
poller *poller poller *poller
} }
// NewWorkers creates and returns a new Workers. // NewLauncher creates and returns a new Launcher.
func NewWorkers(poolSize int, opt *RedisOpt) *Workers { func NewLauncher(poolSize int, opt *RedisOpt) *Launcher {
rdb := redis.NewClient(&redis.Options{Addr: opt.Addr, Password: opt.Password}) rdb := redis.NewClient(&redis.Options{Addr: opt.Addr, Password: opt.Password})
poller := &poller{ poller := &poller{
rdb: rdb, rdb: rdb,
@ -125,7 +125,7 @@ func NewWorkers(poolSize int, opt *RedisOpt) *Workers {
avgInterval: 5 * time.Second, avgInterval: 5 * time.Second,
zsets: []string{scheduled, retry}, zsets: []string{scheduled, retry},
} }
return &Workers{ return &Launcher{
rdb: rdb, rdb: rdb,
poller: poller, poller: poller,
poolTokens: make(chan struct{}, poolSize), poolTokens: make(chan struct{}, poolSize),
@ -135,8 +135,8 @@ func NewWorkers(poolSize int, opt *RedisOpt) *Workers {
// TaskHandler handles a given task and report any error. // TaskHandler handles a given task and report any error.
type TaskHandler func(*Task) error type TaskHandler func(*Task) error
// Run starts the workers and scheduler with a given handler. // Start starts the workers and scheduler with a given handler.
func (w *Workers) Run(handler TaskHandler) { func (w *Launcher) Start(handler TaskHandler) {
if w.running { if w.running {
return return
} }