From 461d922616b5343deb523ac1603f55302e261986 Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Date: Sat, 19 Oct 2024 09:05:17 +0300 Subject: [PATCH] docs: apply recommendaded updates * additionally, we log an erro in the case the redis client cannot shutdown in the scheduler --- client.go | 4 ++-- inspector.go | 4 ++-- scheduler.go | 8 +++++--- server.go | 8 ++++---- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/client.go b/client.go index a54e0bcf5..e440d0972 100644 --- a/client.go +++ b/client.go @@ -41,8 +41,8 @@ func NewClient(r RedisConnOpt) *Client { return client } -// NewClientFromRedisClient returns a new Client instance given a redis client. -// Warning: the redis client will not be closed by Asynq, you are responsible for closing. +// NewClientFromRedisClient returns a new instance of Client given a redis.UniversalClient +// Warning: The underlying redis connection pool will not be closed by Asynq, you are responsible for closing it. func NewClientFromRedisClient(c redis.UniversalClient) *Client { return &Client{broker: rdb.NewRDB(c), sharedConnection: true} } diff --git a/inspector.go b/inspector.go index 5990390f4..e361d229f 100644 --- a/inspector.go +++ b/inspector.go @@ -36,8 +36,8 @@ func NewInspector(r RedisConnOpt) *Inspector { return inspector } -// NewFromRedisClient returns a new instance of Inspector. -// Warning: the redis client will not be closed by Asynq, you are responsible for closing. +// NewInspectorFromRedisClient returns a new instance of Inspector given a redis.UniversalClient +// Warning: The underlying redis connection pool will not be closed by Asynq, you are responsible for closing it. func NewInspectorFromRedisClient(c redis.UniversalClient) *Inspector { return &Inspector{ rdb: rdb.NewRDB(c), diff --git a/scheduler.go b/scheduler.go index affbeec44..89ec2efcf 100644 --- a/scheduler.go +++ b/scheduler.go @@ -60,9 +60,9 @@ func NewScheduler(r RedisConnOpt, opts *SchedulerOpts) *Scheduler { return scheduler } -// NewSchedulerFromRedisClient returns a new Scheduler instance given a redis client. +// NewSchedulerFromRedisClient returns a new instance of Scheduler given a redis.UniversalClient // The parameter opts is optional, defaults will be used if opts is set to nil. -// Warning: the redis client will not be closed by Asynq, you are responsible for closing. +// Warning: The underlying redis connection pool will not be closed by Asynq, you are responsible for closing it. func NewSchedulerFromRedisClient(c redis.UniversalClient, opts *SchedulerOpts) *Scheduler { if opts == nil { opts = &SchedulerOpts{} @@ -273,7 +273,9 @@ func (s *Scheduler) Shutdown() { s.wg.Wait() s.clearHistory() - s.client.Close() + if err := s.client.Close(); err != nil { + s.logger.Errorf("Failed to close redis client connection: %v", err) + } if !s.sharedConnection { s.rdb.Close() } diff --git a/server.go b/server.go index d251dc678..41b4eabaf 100644 --- a/server.go +++ b/server.go @@ -106,7 +106,7 @@ type Config struct { // If BaseContext is nil, the default is context.Background(). // If this is defined, then it MUST return a non-nil context BaseContext func() context.Context - + // TaskCheckInterval specifies the interval between checks for new tasks to process when all queues are empty. // // If unset, zero or a negative value, the interval is set to 1 second. @@ -440,9 +440,9 @@ func NewServer(r RedisConnOpt, cfg Config) *Server { return server } -// NewServerFromRedisClient returns a new Server given a redis client -// and server configuration. -// Warning: the redis client will not be closed by Asynq, you are responsible for closing. +// NewServerFromRedisClient returns a new instance of Server given a redis.UniversalClient +// and server configuration +// Warning: The underlying redis connection pool will not be closed by Asynq, you are responsible for closing it. func NewServerFromRedisClient(c redis.UniversalClient, cfg Config) *Server { baseCtxFn := cfg.BaseContext if baseCtxFn == nil {