2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-25 15:22:18 +08:00

fix: closing the Client also closes the broker

* The error was also previously unhandled. For shared connections an error will be returned by the broker itself because the sharedConnection bool is also set on the client. This also means we can get rid of the sharedConnection flag on the Scheduler itself and let it work internally.
This commit is contained in:
Mohammed Sohail 2024-12-03 10:27:50 +03:00
parent ee17997650
commit f1e7dc4056
No known key found for this signature in database
GPG Key ID: 7DD45520C01CD85D

View File

@ -44,9 +44,6 @@ type Scheduler struct {
// to avoid using cron.EntryID as the public API of
// the Scheduler.
idmap map[string]cron.EntryID
// When a Scheduler has been created with an existing Redis connection, we do
// not want to close it.
sharedConnection bool
}
const defaultHeartbeatInterval = 10 * time.Second
@ -65,7 +62,6 @@ func NewScheduler(r RedisConnOpt, opts *SchedulerOpts) *Scheduler {
scheduler.rdb = rdb
scheduler.client = &Client{broker: rdb, sharedConnection: false}
scheduler.sharedConnection = false
return scheduler
}
@ -78,7 +74,6 @@ func NewSchedulerFromRedisClient(c redis.UniversalClient, opts *SchedulerOpts) *
scheduler.rdb = rdb.NewRDB(c)
scheduler.client = NewClientFromRedisClient(c)
scheduler.sharedConnection = true
return scheduler
}
@ -309,9 +304,6 @@ func (s *Scheduler) Shutdown() {
if err := s.client.Close(); err != nil {
s.logger.Errorf("Failed to close redis client connection: %v", err)
}
if !s.sharedConnection {
s.rdb.Close()
}
s.logger.Info("Scheduler stopped")
}