Skip to content

Commit 770cf18

Browse files
committed
remove duplicate of duplicate
1 parent a3ae78d commit 770cf18

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

packages/service-library/src/servicelib/redis/_client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from redis.asyncio.lock import Lock
1111
from redis.asyncio.retry import Retry
1212
from redis.backoff import ExponentialBackoff
13+
from servicelib.async_utils import cancel_wait_task
1314
from tenacity import retry
1415
from yarl import URL
1516

@@ -20,9 +21,9 @@
2021
DEFAULT_HEALTH_CHECK_INTERVAL,
2122
DEFAULT_LOCK_TTL,
2223
DEFAULT_SOCKET_TIMEOUT,
24+
SHUTDOWN_TIMEOUT_S,
2325
)
2426
from ._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)

packages/service-library/src/servicelib/redis/_utils.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import logging
32
from collections.abc import Awaitable
43
from typing import Any
@@ -7,21 +6,11 @@
76
from redis.asyncio.lock import Lock
87

98
from ..logging_utils import log_context
10-
from ._constants import SHUTDOWN_TIMEOUT_S
119
from ._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-
2514
async def auto_extend_lock(lock: Lock) -> None:
2615
try:
2716
with log_context(_logger, logging.DEBUG, f"Autoextend lock {lock.name!r}"):

0 commit comments

Comments
 (0)