Skip to content

Commit

Permalink
fix: async setup of webhooks queue
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bluhm <[email protected]>
  • Loading branch information
dbluhm committed Apr 25, 2022
1 parent 2d631bb commit 10031b5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions echo_agent/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
5 changes: 4 additions & 1 deletion echo_agent/webhook_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 10031b5

Please sign in to comment.