File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
packages/service-library/src/servicelib/redis Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 88
99import redis .asyncio as aioredis
1010import redis .exceptions
11+ import tenacity
1112from common_library .async_tools import cancel_wait_task
1213from redis .asyncio .lock import Lock
1314from redis .asyncio .retry import Retry
@@ -62,6 +63,16 @@ def __post_init__(self) -> None:
6263 self ._is_healthy = False
6364 self ._health_check_task_started_event = asyncio .Event ()
6465
66+ @tenacity .retry (
67+ wait = tenacity .wait_fixed (2 ),
68+ stop = tenacity .stop_after_delay (20 ),
69+ before_sleep = tenacity .before_sleep_log (_logger , logging .INFO ),
70+ reraise = True ,
71+ )
72+ async def wait_till_redis_is_responsive (self ) -> None :
73+ if not await self .ping ():
74+ raise tenacity .TryAgain
75+
6576 async def setup (self ) -> None :
6677 @periodic (interval = self .health_check_interval )
6778 async def _periodic_check_health () -> None :
@@ -78,7 +89,7 @@ async def _periodic_check_health() -> None:
7889 # - ensure redis is working
7990 # - before shutting down an initialized Redis connection it must
8091 # make at least one call to the server, otherwise tests might hang
81- await self .ping ()
92+ await self .wait_till_redis_is_responsive ()
8293
8394 _logger .info (
8495 "Connection to %s succeeded with %s" ,
You can’t perform that action at this time.
0 commit comments