Spaces:
Sleeping
Sleeping
File size: 949 Bytes
62516b8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | from __future__ import annotations
from src.config import settings
class WebhookCallbackClient:
def __init__(self) -> None:
self._client = None
async def initialize(self) -> None:
if self._client is not None:
return
try:
import httpx
except ImportError as exc:
raise RuntimeError("httpx package is required for webhook callback.") from exc
self._client = httpx.AsyncClient(
timeout=settings.webhook_callback_timeout_seconds,
)
async def shutdown(self) -> None:
if self._client is None:
return
await self._client.aclose()
self._client = None
async def send_json(self, *, callback_url: str, payload: dict) -> None:
await self.initialize()
assert self._client is not None
response = await self._client.post(callback_url, json=payload)
response.raise_for_status()
|