Skip to content

Commit

Permalink
[RFC] Adds Ping() to client/scheduler/server (#585)
Browse files Browse the repository at this point in the history
* [RFC] Adds Ping() to client/scheduler/server

* Checks for scheduler state closed
  • Loading branch information
pbarnum authored Oct 19, 2024
1 parent 0dc670d commit b1e1389
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@ func (c *Client) EnqueueContext(ctx context.Context, task *Task, opts ...Option)
return newTaskInfo(msg, state, opt.processAt, nil), nil
}

// Ping performs a ping against the redis connection.
func (c *Client) Ping() error {
return c.broker.Ping()
}

func (c *Client) enqueue(ctx context.Context, msg *base.TaskMessage, uniqueTTL time.Duration) error {
if uniqueTTL > 0 {
return c.broker.EnqueueUnique(ctx, msg, uniqueTTL)
Expand Down
11 changes: 11 additions & 0 deletions scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,14 @@ func (s *Scheduler) clearHistory() {
}
}
}

// Ping performs a ping against the redis connection.
func (s *Scheduler) Ping() error {
s.state.mu.Lock()
defer s.state.mu.Unlock()
if s.state.value == srvStateClosed {
return nil
}

return s.rdb.Ping()
}
15 changes: 14 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ func (srv *Server) Shutdown() {
func (srv *Server) Stop() {
srv.state.mu.Lock()
if srv.state.value != srvStateActive {
// Invalid calll to Stop, server can only go from Active state to Stopped state.
// Invalid call to Stop, server can only go from Active state to Stopped state.
srv.state.mu.Unlock()
return
}
Expand All @@ -770,3 +770,16 @@ func (srv *Server) Stop() {
srv.processor.stop()
srv.logger.Info("Processor stopped")
}

// Ping performs a ping against the redis connection.
//
// This is an alternative to the HealthCheckFunc available in the Config object.
func (srv *Server) Ping() error {
srv.state.mu.Lock()
defer srv.state.mu.Unlock()
if srv.state.value == srvStateClosed {
return nil
}

return srv.broker.Ping()
}

0 comments on commit b1e1389

Please sign in to comment.