Skip to content

Commit

Permalink
fix: closing the Client also closes the broker
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
kamikazechaser committed Dec 3, 2024
1 parent ee17997 commit f1e7dc4
Showing 1 changed file with 0 additions and 8 deletions.
8 changes: 0 additions & 8 deletions scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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")
}

Expand Down

0 comments on commit f1e7dc4

Please sign in to comment.