[GH-ISSUE #155] [FEATURE REQUEST] Add ability to check heartbeat? #1061

Closed
opened 2026-03-07 22:05:00 +03:00 by kerem · 5 comments
Owner

Originally created by @jimmy-ho on GitHub (May 28, 2020).
Original GitHub issue: https://github.com/hibiken/asynq/issues/155

Originally assigned to: @hibiken on GitHub.

I would like to call into either the *asynq.Client or *asynq.Server for whether they are healthy - ie. can connect to redis etc.

It seems at the moment this is not possible, I want this so my health-check route can come back with a valid response if they are not well.

Hopefully not something hard to add, or if you can enlighten me how to get this status (if available). Thanks!

Maybe a quick:

healthy := true

_, err := r.redisClient.Ping().Result()
if err != nil {
	return false
}

return healthy
Originally created by @jimmy-ho on GitHub (May 28, 2020). Original GitHub issue: https://github.com/hibiken/asynq/issues/155 Originally assigned to: @hibiken on GitHub. I would like to call into either the *asynq.Client or *asynq.Server for whether they are healthy - ie. can connect to redis etc. It seems at the moment this is not possible, I want this so my health-check route can come back with a valid response if they are not well. Hopefully not something hard to add, or if you can enlighten me how to get this status (if available). Thanks! Maybe a quick: ``` healthy := true _, err := r.redisClient.Ping().Result() if err != nil { return false } return healthy ```
kerem 2026-03-07 22:05:00 +03:00
Author
Owner

@hibiken commented on GitHub (May 28, 2020):

@jimmy-ho Thanks for opening this issue!

This is a good feature request. It's something we can (and probably should) add to asynq.Server.

For context:
Current implementation has a "heartbeater" goroutine that periodically writes server state to redis (so that we can inspect it with asynq servers and asynq workers CLI commands).
And I think we can leverage that goroutine to check whether the server can talk to redis and expose an API to surface that health check result.

Let me look into this a bit more and try to come up with a proposal. In the meantime, if you or anyone have suggestions on how the API should look, feel free to suggest in this thread. Thanks!

<!-- gh-comment-id:635375230 --> @hibiken commented on GitHub (May 28, 2020): @jimmy-ho Thanks for opening this issue! This is a good feature request. It's something we can (and probably should) add to `asynq.Server`. For context: Current implementation has a "heartbeater" goroutine that periodically writes server state to redis (so that we can inspect it with `asynq servers` and `asynq workers` CLI commands). And I think we can leverage that goroutine to check whether the server can talk to redis and expose an API to surface that health check result. Let me look into this a bit more and try to come up with a proposal. In the meantime, if you or anyone have suggestions on how the API should look, feel free to suggest in this thread. Thanks!
Author
Owner

@hibiken commented on GitHub (Jul 24, 2020):

Initial Proposal

Add HealthCheckFunc in Config:

type Config struct {
     // HealthCheckFunc is called periodically with any error encountered during ping to connected redis server.
     HealthCheckFunc func(error)

     // HealthCheckInterval specifies the interval between healthchecks.
     // By default the interval is 5 seconds.
     HealthCheckInterval time.Duration
}

By integrating with monitoring and alert system (e.g. Prometheus), users can monitor asynq.Server's health and alert if the server is having issues.

<!-- gh-comment-id:663548621 --> @hibiken commented on GitHub (Jul 24, 2020): ### Initial Proposal Add `HealthCheckFunc` in `Config`: ```go type Config struct { // HealthCheckFunc is called periodically with any error encountered during ping to connected redis server. HealthCheckFunc func(error) // HealthCheckInterval specifies the interval between healthchecks. // By default the interval is 5 seconds. HealthCheckInterval time.Duration } ``` By integrating with monitoring and alert system (e.g. Prometheus), users can monitor asynq.Server's health and alert if the server is having issues.
Author
Owner

@a5r0n commented on GitHub (Apr 27, 2022):

i think we should expose the healthcheck in the asynq.Client as well,
e.g. i have REST API to manage tasks and Add them to queue using the client, and i have to add healthcheck to API to let k8s to manage this pod,
@hibiken should i open new issue?

<!-- gh-comment-id:1111085870 --> @a5r0n commented on GitHub (Apr 27, 2022): i think we should expose the healthcheck in the `asynq.Client` as well, e.g. i have REST API to manage tasks and Add them to queue using the client, and i have to add healthcheck to API to let k8s to manage this pod, @hibiken should i open new issue?
Author
Owner

@hibiken commented on GitHub (Apr 29, 2022):

@a5r0n thanks for the comment, I think that makes sense. Client can expose the health of the backend resource (Redis in our case). I've been meaning to revisit how we do health checks of Redis (Redis is a critical backend for both Client and Server instances and we should expose a API to check the health). Please feel free to open a new issue 👍

<!-- gh-comment-id:1113825094 --> @hibiken commented on GitHub (Apr 29, 2022): @a5r0n thanks for the comment, I think that makes sense. `Client` can expose the health of the backend resource (Redis in our case). I've been meaning to revisit how we do health checks of Redis (Redis is a critical backend for both `Client` and `Server` instances and we should expose a API to check the health). Please feel free to open a new issue 👍
Author
Owner

@bojanz commented on GitHub (Nov 12, 2023):

@hibiken Is https://github.com/hibiken/asynq/pull/585 enough, or should I go ahead and create a separate issue as well?

<!-- gh-comment-id:1807267217 --> @bojanz commented on GitHub (Nov 12, 2023): @hibiken Is https://github.com/hibiken/asynq/pull/585 enough, or should I go ahead and create a separate issue as well?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asynq#1061
No description provided.