File tree Expand file tree Collapse file tree 2 files changed +5
-13
lines changed
packages/service-library/src/servicelib/redis Expand file tree Collapse file tree 2 files changed +5
-13
lines changed Original file line number Diff line number Diff line change 1010from redis .asyncio .lock import Lock
1111from redis .asyncio .retry import Retry
1212from redis .backoff import ExponentialBackoff
13+ from servicelib .async_utils import cancel_wait_task
1314from tenacity import retry
1415from yarl import URL
1516
2021 DEFAULT_HEALTH_CHECK_INTERVAL ,
2122 DEFAULT_LOCK_TTL ,
2223 DEFAULT_SOCKET_TIMEOUT ,
24+ SHUTDOWN_TIMEOUT_S ,
2325)
2426from ._errors import CouldNotConnectToRedisError
25- from ._utils import cancel_or_warn
2627
2728_logger = logging .getLogger (__name__ )
2829
@@ -82,7 +83,9 @@ async def setup(self) -> None:
8283 async def shutdown (self ) -> None :
8384 if self ._health_check_task :
8485 self ._continue_health_checking = False
85- await cancel_or_warn (self ._health_check_task )
86+ await cancel_wait_task (
87+ self ._health_check_task , max_delay = SHUTDOWN_TIMEOUT_S
88+ )
8689 self ._health_check_task = None
8790
8891 await self ._client .aclose (close_connection_pool = True )
Original file line number Diff line number Diff line change 1- import asyncio
21import logging
32from collections .abc import Awaitable
43from typing import Any
76from redis .asyncio .lock import Lock
87
98from ..logging_utils import log_context
10- from ._constants import SHUTDOWN_TIMEOUT_S
119from ._errors import LockLostError
1210
1311_logger = logging .getLogger (__name__ )
1412
1513
16- async def cancel_or_warn (task : asyncio .Task ) -> None :
17- if not task .cancelled ():
18- task .cancel ()
19- _ , pending = await asyncio .wait ((task ,), timeout = SHUTDOWN_TIMEOUT_S )
20- if pending :
21- task_name = task .get_name ()
22- _logger .warning ("Could not cancel task_name=%s pending=%s" , task_name , pending )
23-
24-
2514async def auto_extend_lock (lock : Lock ) -> None :
2615 try :
2716 with log_context (_logger , logging .DEBUG , f"Autoextend lock { lock .name !r} " ):
You can’t perform that action at this time.
0 commit comments