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
4 changes: 4 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ func (c *Client) Queues() *Queues {
return &Queues{client: c}
}

func (c *Client) Readiness() *Readiness {
return &Readiness{client: c}
}

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

import (
"net/http"
)

// Readiness provides access to the readiness endpoint.
type Readiness struct {
client *Client
}

// ReadinessResponse represents the response from the readiness endpoint.
type ReadinessResponse struct {
// Ready indicates whether QStash is ready to accept requests.
Ready bool `json:"ready"`
}

// Check retrieves the readiness status of QStash.
func (r *Readiness) Check() (ReadinessResponse, error) {
opts := requestOptions{
method: http.MethodGet,
path: "/v2/readiness",
}
response, _, err := r.client.fetchWith(opts)
if err != nil {
return ReadinessResponse{}, err
}
readiness, err := parse[ReadinessResponse](response)
return readiness, err
}
14 changes: 14 additions & 0 deletions readiness_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package qstash

import (
"github.com/stretchr/testify/assert"
"testing"
)

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

readiness, err := client.Readiness().Check()
assert.NoError(t, err)
assert.True(t, readiness.Ready)
}
Loading