From f4fa9ca00bf4798249cbab24bd3c69043f0314be Mon Sep 17 00:00:00 2001 From: Matthias Veit Date: Wed, 25 Sep 2024 09:09:14 +0200 Subject: [PATCH] [fix] Wait for pub-sub messages to arrive (#28) --- fixcloudutils/redis/pub_sub.py | 3 ++- pyproject.toml | 2 +- tests/conftest.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/fixcloudutils/redis/pub_sub.py b/fixcloudutils/redis/pub_sub.py index 1d4df7c..e506559 100644 --- a/fixcloudutils/redis/pub_sub.py +++ b/fixcloudutils/redis/pub_sub.py @@ -64,7 +64,8 @@ def __init__(self, redis: Redis, channel: str, handler: MessageHandler) -> None: async def start(self) -> None: async def read_messages(pubsub: PubSub) -> None: while True: - msg = await pubsub.get_message(ignore_subscribe_messages=True) + # timeout: waiting time for a message to be received in seconds + msg = await pubsub.get_message(ignore_subscribe_messages=True, timeout=30) try: if msg is not None: data = json.loads(msg["data"]) diff --git a/pyproject.toml b/pyproject.toml index c10b309..0a39c27 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "fixcloudutils" -version = "1.15.0" +version = "1.15.1" authors = [{ name = "Some Engineering Inc." }] description = "Utilities for fixcloud." license = { file = "LICENSE" } diff --git a/tests/conftest.py b/tests/conftest.py index e6df020..c82ad02 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -68,7 +68,7 @@ async def eventually( @fixture async def redis() -> AsyncIterator[Redis]: - backoff = ExponentialBackoff() # type: ignore + backoff = ExponentialBackoff() redis = Redis(host="localhost", port=6379, db=0, decode_responses=True, retry=Retry(backoff, 10)) await redis.flushdb() # wipe redis yield redis