mirror of
https://github.com/hibiken/asynq.git
synced 2024-12-25 23:32:17 +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:
parent
ee17997650
commit
f1e7dc4056
@ -44,9 +44,6 @@ type Scheduler struct {
|
|||||||
// to avoid using cron.EntryID as the public API of
|
// to avoid using cron.EntryID as the public API of
|
||||||
// the Scheduler.
|
// the Scheduler.
|
||||||
idmap map[string]cron.EntryID
|
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
|
const defaultHeartbeatInterval = 10 * time.Second
|
||||||
@ -65,7 +62,6 @@ func NewScheduler(r RedisConnOpt, opts *SchedulerOpts) *Scheduler {
|
|||||||
|
|
||||||
scheduler.rdb = rdb
|
scheduler.rdb = rdb
|
||||||
scheduler.client = &Client{broker: rdb, sharedConnection: false}
|
scheduler.client = &Client{broker: rdb, sharedConnection: false}
|
||||||
scheduler.sharedConnection = false
|
|
||||||
|
|
||||||
return scheduler
|
return scheduler
|
||||||
}
|
}
|
||||||
@ -78,7 +74,6 @@ func NewSchedulerFromRedisClient(c redis.UniversalClient, opts *SchedulerOpts) *
|
|||||||
|
|
||||||
scheduler.rdb = rdb.NewRDB(c)
|
scheduler.rdb = rdb.NewRDB(c)
|
||||||
scheduler.client = NewClientFromRedisClient(c)
|
scheduler.client = NewClientFromRedisClient(c)
|
||||||
scheduler.sharedConnection = true
|
|
||||||
|
|
||||||
return scheduler
|
return scheduler
|
||||||
}
|
}
|
||||||
@ -309,9 +304,6 @@ func (s *Scheduler) Shutdown() {
|
|||||||
if err := s.client.Close(); err != nil {
|
if err := s.client.Close(); err != nil {
|
||||||
s.logger.Errorf("Failed to close redis client connection: %v", err)
|
s.logger.Errorf("Failed to close redis client connection: %v", err)
|
||||||
}
|
}
|
||||||
if !s.sharedConnection {
|
|
||||||
s.rdb.Close()
|
|
||||||
}
|
|
||||||
s.logger.Info("Scheduler stopped")
|
s.logger.Info("Scheduler stopped")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user