Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,38 @@ func (c *Client) Queues() *Queues {
return &Queues{client: c}
}

// ReadinessResponse represents the response from the readiness endpoint.
type ReadinessResponse struct {
// Success indicates whether the service is ready.
Success bool `json:"success"`
// Message provides additional information about the readiness status.
Message string `json:"message,omitempty"`
// StatusCode is the HTTP status code returned by the endpoint.
StatusCode int `json:"-"`
}

// Readiness checks if the QStash service is ready to accept requests.
func (c *Client) Readiness() (result ReadinessResponse, err error) {
opts := requestOptions{
method: http.MethodGet,
path: "/v2/readiness",
}
response, statusCode, err := c.fetchWith(opts)
if err != nil {
return ReadinessResponse{
Success: false,
Message: err.Error(),
StatusCode: statusCode,
}, err
}
result, err = parse[ReadinessResponse](response)
result.StatusCode = statusCode
if statusCode >= 200 && statusCode < 300 {
result.Success = true
}
return
}

type requestOptions struct {
method string
path string
Expand Down
17 changes: 17 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package qstash

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestReadiness(t *testing.T) {
client := NewClientWithEnv()

res, err := client.Readiness()
assert.NoError(t, err)
assert.True(t, res.Success)
assert.GreaterOrEqual(t, res.StatusCode, 200)
assert.Less(t, res.StatusCode, 300)
}
Loading