mirror of
https://github.com/hibiken/asynq.git
synced 2024-12-26 07:42:17 +08:00
feat(periodic_task_manager): Add RedisUniversalClient support (#958)
Signed-off-by: Xijun Dai <daixijun1990@gmail.com>
This commit is contained in:
parent
80479b528d
commit
12cbba4926
@ -10,6 +10,8 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PeriodicTaskManager manages scheduling of periodic tasks.
|
// PeriodicTaskManager manages scheduling of periodic tasks.
|
||||||
@ -27,9 +29,12 @@ type PeriodicTaskManagerOpts struct {
|
|||||||
// Required: must be non nil
|
// Required: must be non nil
|
||||||
PeriodicTaskConfigProvider PeriodicTaskConfigProvider
|
PeriodicTaskConfigProvider PeriodicTaskConfigProvider
|
||||||
|
|
||||||
// Required: must be non nil
|
// Optional: if RedisUniversalClient is nil must be non nil
|
||||||
RedisConnOpt RedisConnOpt
|
RedisConnOpt RedisConnOpt
|
||||||
|
|
||||||
|
// Optional: if RedisUniversalClient is non nil, RedisConnOpt is ignored.
|
||||||
|
RedisUniversalClient redis.UniversalClient
|
||||||
|
|
||||||
// Optional: scheduler options
|
// Optional: scheduler options
|
||||||
*SchedulerOpts
|
*SchedulerOpts
|
||||||
|
|
||||||
@ -45,10 +50,16 @@ func NewPeriodicTaskManager(opts PeriodicTaskManagerOpts) (*PeriodicTaskManager,
|
|||||||
if opts.PeriodicTaskConfigProvider == nil {
|
if opts.PeriodicTaskConfigProvider == nil {
|
||||||
return nil, fmt.Errorf("PeriodicTaskConfigProvider cannot be nil")
|
return nil, fmt.Errorf("PeriodicTaskConfigProvider cannot be nil")
|
||||||
}
|
}
|
||||||
if opts.RedisConnOpt == nil {
|
if opts.RedisConnOpt == nil && opts.RedisUniversalClient == nil {
|
||||||
return nil, fmt.Errorf("RedisConnOpt cannot be nil")
|
return nil, fmt.Errorf("RedisConnOpt/RedisUniversalClient cannot be nil")
|
||||||
}
|
}
|
||||||
scheduler := NewScheduler(opts.RedisConnOpt, opts.SchedulerOpts)
|
var scheduler *Scheduler
|
||||||
|
if opts.RedisUniversalClient != nil {
|
||||||
|
scheduler = NewSchedulerFromRedisClient(opts.RedisUniversalClient, opts.SchedulerOpts)
|
||||||
|
} else {
|
||||||
|
scheduler = NewScheduler(opts.RedisConnOpt, opts.SchedulerOpts)
|
||||||
|
}
|
||||||
|
|
||||||
syncInterval := opts.SyncInterval
|
syncInterval := opts.SyncInterval
|
||||||
if syncInterval == 0 {
|
if syncInterval == 0 {
|
||||||
syncInterval = defaultSyncInterval
|
syncInterval = defaultSyncInterval
|
||||||
|
Loading…
Reference in New Issue
Block a user