diff --git a/echo_agent/app.py b/echo_agent/app.py index 87f2b7b..10d5cce 100644 --- a/echo_agent/app.py +++ b/echo_agent/app.py @@ -52,6 +52,11 @@ app = FastAPI(title="Echo Agent", version="0.1.0") +@app.on_event("startup") +async def setup_webhook_queue(): + await webhooks.setup() + + ConnectionInfo = dataclasses.dataclass(ConnectionInfoDataclass) diff --git a/echo_agent/webhook_queue.py b/echo_agent/webhook_queue.py index b2a9605..5cff3ad 100644 --- a/echo_agent/webhook_queue.py +++ b/echo_agent/webhook_queue.py @@ -12,9 +12,12 @@ def __init__( condition: Optional[Callable[[QueueEntry], bool]] = None, ): self._queue: List[Any] = [] - self._cond = asyncio.Condition() + self._cond: Optional[asyncio.Condition] = None self.condition = condition + async def setup(self): + self._cond = asyncio.Condition() + def _first_matching_index(self, condition: Callable[[QueueEntry], bool]): for index, entry in enumerate(self._queue): if condition(entry): diff --git a/tests/conftest.py b/tests/conftest.py index 1571f1c..986dc46 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,9 +1,11 @@ import pytest from echo_agent import EchoClient +from echo_agent.app import webhooks @pytest.fixture async def echo_client(): from echo_agent import app + await webhooks.setup() yield EchoClient(base_url="http://test", app=app)