Skip to content
Closed
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
2 changes: 1 addition & 1 deletion pipegate/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def handle_request(
typer.echo(f"Error processing request {request.correlation_id}: {e}", err=True)
payload = BufferGateResponse(
correlation_id=request.correlation_id,
headers="",
headers="{}",
body="",
status_code=504,
)
Expand Down
18 changes: 10 additions & 8 deletions pipegate/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,16 @@ async def handle_http_request(
detail=f"Request body exceeds limit of {settings.max_body_bytes} bytes",
)

loop = asyncio.get_event_loop()
future: asyncio.Future[BufferGateResponse] = loop.create_future()
running_loop = asyncio.get_running_loop()
future: asyncio.Future[BufferGateResponse] = running_loop.create_future()
futures[correlation_id] = future

if connection_id not in buffers:
buffers[connection_id] = asyncio.Queue(maxsize=settings.max_queue_depth)
queue = buffers.setdefault(
connection_id, asyncio.Queue(maxsize=settings.max_queue_depth)
)

try:
buffers[connection_id].put_nowait(
queue.put_nowait(
BufferGateRequest(
correlation_id=correlation_id,
method=cast(Methods, request.method),
Expand Down Expand Up @@ -147,8 +148,9 @@ async def handle_websocket(
await websocket.accept()
logger.info("WebSocket connected: %s", connection_id)

if connection_id not in buffers:
buffers[connection_id] = asyncio.Queue(maxsize=settings.max_queue_depth)
queue = buffers.setdefault(
connection_id, asyncio.Queue(maxsize=settings.max_queue_depth)
)

async def receive() -> None:
try:
Expand All @@ -170,7 +172,7 @@ async def receive() -> None:

async def send() -> None:
while True:
request = await buffers[connection_id].get()
request = await queue.get()
try:
await websocket.send_text(request.model_dump_json())
except WebSocketDisconnect:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dev = [
[tool.pytest.ini_options]
testpaths = ["tests"]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"

[tool.ruff]
target-version = "py312"
Expand Down
Loading