Skip to content

Commit

Permalink
Increase asyinc waiting time for RabbitMQ subscriber (#168)
Browse files Browse the repository at this point in the history
* Increase asying waiting time for RabbitMQ subscriber

* Await `callback()` as well

Co-authored-by: Stef Piatek <s.piatek@ucl.ac.uk>

---------

Co-authored-by: Stef Piatek <s.piatek@ucl.ac.uk>
  • Loading branch information
milanmlft and stefpiatek authored Dec 4, 2023
1 parent 0195754 commit 1405b86
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions pixl_core/src/core/patient_queue/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ async def run(self, callback: Callable[[bytes], Awaitable[None]]) -> None:
async with self._queue.iterator() as queue_iter:
async for message in queue_iter:
if not self.token_bucket.has_token:
await asyncio.gather(
message.reject(requeue=True),
asyncio.sleep(1e-3),
)
await asyncio.sleep(0.01)
await message.reject(requeue=True)
continue

# Messages need to be acknowledged before a callback otherwise
Expand All @@ -72,10 +70,8 @@ async def run(self, callback: Callable[[bytes], Awaitable[None]]) -> None:
await message.ack()

try:
await asyncio.gather(
callback(message.body),
asyncio.sleep(1e-3), # Avoid very fast callbacks
)
await asyncio.sleep(0.01) # Avoid very fast callbacks
await callback(message.body)
except Exception:
LOGGER.exception(
"Failed to process %s" "Not re-queuing message",
Expand Down

0 comments on commit 1405b86

Please sign in to comment.