diff --git a/qstash/__init__.py b/qstash/__init__.py index 56e80a6..2b2b6ad 100644 --- a/qstash/__init__.py +++ b/qstash/__init__.py @@ -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"] diff --git a/qstash/asyncio/client.py b/qstash/asyncio/client.py index b830d15..43e0ad4 100644 --- a/qstash/asyncio/client.py +++ b/qstash/asyncio/client.py @@ -1,3 +1,4 @@ +import dataclasses from os import environ from typing import Literal, Optional, Union @@ -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, @@ -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)) diff --git a/qstash/client.py b/qstash/client.py index 72fe4e5..8f04edd 100644 --- a/qstash/client.py +++ b/qstash/client.py @@ -1,3 +1,4 @@ +import dataclasses from os import environ from typing import Optional, Union, Literal @@ -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.""" @@ -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)) diff --git a/tests/asyncio/test_readiness.py b/tests/asyncio/test_readiness.py new file mode 100644 index 0000000..8ff0b36 --- /dev/null +++ b/tests/asyncio/test_readiness.py @@ -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 diff --git a/tests/test_readiness.py b/tests/test_readiness.py new file mode 100644 index 0000000..0e99781 --- /dev/null +++ b/tests/test_readiness.py @@ -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