Skip to content

Commit f1e7dc4

Browse files
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.
1 parent ee17997 commit f1e7dc4

File tree

1 file changed

+0
-8
lines changed

1 file changed

+0
-8
lines changed

scheduler.go

-8
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ type Scheduler struct {
4444
// to avoid using cron.EntryID as the public API of
4545
// the Scheduler.
4646
idmap map[string]cron.EntryID
47-
// When a Scheduler has been created with an existing Redis connection, we do
48-
// not want to close it.
49-
sharedConnection bool
5047
}
5148

5249
const defaultHeartbeatInterval = 10 * time.Second
@@ -65,7 +62,6 @@ func NewScheduler(r RedisConnOpt, opts *SchedulerOpts) *Scheduler {
6562

6663
scheduler.rdb = rdb
6764
scheduler.client = &Client{broker: rdb, sharedConnection: false}
68-
scheduler.sharedConnection = false
6965

7066
return scheduler
7167
}
@@ -78,7 +74,6 @@ func NewSchedulerFromRedisClient(c redis.UniversalClient, opts *SchedulerOpts) *
7874

7975
scheduler.rdb = rdb.NewRDB(c)
8076
scheduler.client = NewClientFromRedisClient(c)
81-
scheduler.sharedConnection = true
8277

8378
return scheduler
8479
}
@@ -309,9 +304,6 @@ func (s *Scheduler) Shutdown() {
309304
if err := s.client.Close(); err != nil {
310305
s.logger.Errorf("Failed to close redis client connection: %v", err)
311306
}
312-
if !s.sharedConnection {
313-
s.rdb.Close()
314-
}
315307
s.logger.Info("Scheduler stopped")
316308
}
317309

0 commit comments

Comments
 (0)