Skip to content
Open
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
13 changes: 4 additions & 9 deletions core/bus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

import os
import asyncio
import inspect
import logging
from uuid import uuid4
from typing import Any, Awaitable, Callable, Dict, Optional, TypeVar, cast
from typing import Any, Awaitable, Callable, Dict, Optional, TypeVar

import httpx

Expand Down Expand Up @@ -54,7 +53,7 @@ def __init__(

async def _with_retry(
self,
func: Callable[[], Awaitable[T] | T],
func: Callable[[], Awaitable[T]],
*,
label: str,
retries: int,
Expand All @@ -63,10 +62,7 @@ async def _with_retry(
) -> T | None:
for attempt in range(retries + 1):
try:
result = func()
if inspect.isawaitable(result):
return await result
return result
return await func()
except exc_type as exc: # pragma: no cover - logging path
logger.exception("%s failed", label)
add_entry(kind="bus_client_error", data=f"{label} failed: {exc}")
Expand Down Expand Up @@ -167,14 +163,13 @@ async def _arequest(
async def call() -> httpx.Response:
return await self._client.request(method, url, headers=headers, **kwargs)

result = await self._with_retry(
return await self._with_retry(
call,
label=f"{method.upper()} {url}",
retries=retries,
backoff=backoff,
exc_type=httpx.RequestError,
)
return cast(httpx.Response | None, result)

async def publish(
self,
Expand Down
4 changes: 3 additions & 1 deletion server/stripe_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from stripe.error import SignatureVerificationError # type: ignore[attr-defined]

from core.kb import add_entry
import requests
import httpx
import asyncio

app = FastAPI()
stripe.api_key = os.environ.get("STRIPE_SECRET_KEY", "")
Expand All @@ -29,6 +30,7 @@ async def webhook(request: Request) -> Dict[str, str]:
) # type: ignore[no-untyped-call]
except SignatureVerificationError as e:
raise HTTPException(status_code=400, detail=str(e))

add_entry(kind="stripe_event", type=event.get("type"))
for role in ["CFO", "COO", "CEO", "CMO", "CPO"]:
requests.post(
Expand Down
Loading