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: 2 additions & 2 deletions qstash/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from qstash.asyncio.client import AsyncQStash
from qstash.client import QStash
from qstash.client import QStash, ReadinessResponse
from qstash.receiver import Receiver

__version__ = "3.2.0"
__all__ = ["QStash", "AsyncQStash", "Receiver"]
__all__ = ["QStash", "AsyncQStash", "Receiver", "ReadinessResponse"]
23 changes: 23 additions & 0 deletions qstash/asyncio/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dataclasses
from os import environ
from typing import Literal, Optional, Union

Expand All @@ -12,6 +13,12 @@
from qstash.http import RetryConfig


@dataclasses.dataclass
class ReadinessResponse:
ready: bool
"""Whether QStash is ready to accept requests."""


class AsyncQStash:
def __init__(
self,
Expand Down Expand Up @@ -49,3 +56,19 @@ def __init__(

self.dlq = AsyncDlqApi(self.http)
"""Dlq (Dead Letter Queue) api."""

async def readiness(self) -> ReadinessResponse:
"""
Checks the readiness of QStash.

This endpoint can be used to check if QStash is ready to accept
requests. It's useful for health checks and monitoring.

:return: ReadinessResponse containing the ready status.
"""
response = await self.http.request(
path="/v2/readiness",
method="GET",
)

return ReadinessResponse(ready=response.get("ready", False))
23 changes: 23 additions & 0 deletions qstash/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dataclasses
from os import environ
from typing import Optional, Union, Literal

Expand All @@ -11,6 +12,12 @@
from qstash.url_group import UrlGroupApi


@dataclasses.dataclass
class ReadinessResponse:
ready: bool
"""Whether QStash is ready to accept requests."""


class QStash:
"""Synchronous SDK for the Upstash QStash."""

Expand Down Expand Up @@ -50,3 +57,19 @@ def __init__(

self.dlq = DlqApi(self.http)
"""Dlq (Dead Letter Queue) api."""

def readiness(self) -> ReadinessResponse:
"""
Checks the readiness of QStash.

This endpoint can be used to check if QStash is ready to accept
requests. It's useful for health checks and monitoring.

:return: ReadinessResponse containing the ready status.
"""
response = self.http.request(
path="/v2/readiness",
method="GET",
)

return ReadinessResponse(ready=response.get("ready", False))
9 changes: 9 additions & 0 deletions tests/asyncio/test_readiness.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from qstash import AsyncQStash


async def test_readiness(async_client: AsyncQStash) -> None:
response = await async_client.readiness()

assert response is not None
assert isinstance(response.ready, bool)
assert response.ready is True
9 changes: 9 additions & 0 deletions tests/test_readiness.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from qstash import QStash


def test_readiness(client: QStash) -> None:
response = client.readiness()

assert response is not None
assert isinstance(response.ready, bool)
assert response.ready is True
Loading