Skip to content

Commit

Permalink
feat(periodic_task_manager): Add RedisUniversalClient support
Browse files Browse the repository at this point in the history
Signed-off-by: Xijun Dai <daixijun1990@gmail.com>
  • Loading branch information
daixijun committed Nov 6, 2024
1 parent 580d69e commit 29b922e
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions periodic_task_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"sort"
"sync"
"time"

"github.com/redis/go-redis/v9"
)

// PeriodicTaskManager manages scheduling of periodic tasks.
Expand All @@ -27,9 +29,12 @@ type PeriodicTaskManagerOpts struct {
// Required: must be non nil
PeriodicTaskConfigProvider PeriodicTaskConfigProvider

// Required: must be non nil
// Optional: if RedisUniversalClient is nil must be non nil
RedisConnOpt RedisConnOpt

// Optional: if RedisUniversalClient is non nil, RedisConnOpt is ignored.
RedisUniversalClient redis.UniversalClient

// Optional: scheduler options
*SchedulerOpts

Expand All @@ -45,10 +50,16 @@ func NewPeriodicTaskManager(opts PeriodicTaskManagerOpts) (*PeriodicTaskManager,
if opts.PeriodicTaskConfigProvider == nil {
return nil, fmt.Errorf("PeriodicTaskConfigProvider cannot be nil")
}
if opts.RedisConnOpt == nil {
return nil, fmt.Errorf("RedisConnOpt cannot be nil")
if opts.RedisConnOpt == nil && opts.RedisUniversalClient == 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
if syncInterval == 0 {
syncInterval = defaultSyncInterval
Expand Down

0 comments on commit 29b922e

Please sign in to comment.