mirror of
https://github.com/hibiken/asynq.git
synced 2025-10-23 22:26:13 +08:00
[RFC] Adds Ping() to client/scheduler/server
This commit is contained in:
@@ -405,6 +405,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)
|
||||
|
@@ -320,3 +320,8 @@ func (s *Scheduler) clearHistory() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ping performs a ping against the redis connection.
|
||||
func (s *Scheduler) Ping() error {
|
||||
return s.rdb.Ping()
|
||||
}
|
||||
|
15
server.go
15
server.go
@@ -686,7 +686,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
|
||||
}
|
||||
@@ -697,3 +697,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()
|
||||
}
|
||||
|
Reference in New Issue
Block a user