Skip to content

Commit cfe5917

Browse files
committed
rename
1 parent d502eaa commit cfe5917

File tree

39 files changed

+88
-81
lines changed

39 files changed

+88
-81
lines changed

packages/celery-library/src/celery_library/task.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
AbortableTask,
1313
)
1414
from celery.exceptions import Ignore # type: ignore[import-untyped]
15-
from common_library.async_tools import cancel_and_wait
15+
from common_library.async_tools import cancel_and_shielded_wait
1616
from pydantic import NonNegativeInt
1717
from servicelib.celery.models import TaskID
1818

@@ -62,7 +62,7 @@ async def abort_monitor():
6262
abortable_result = AbortableAsyncResult(task_id, app=app)
6363
while not main_task.done():
6464
if abortable_result.is_aborted():
65-
await cancel_and_wait(
65+
await cancel_and_shielded_wait(
6666
main_task,
6767
max_delay=_DEFAULT_CANCEL_TASK_TIMEOUT.total_seconds(),
6868
)

packages/common-library/src/common_library/async_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async def maybe_await(
6969
return obj
7070

7171

72-
async def cancel_and_wait(
72+
async def cancel_and_shielded_wait(
7373
task: asyncio.Task, *, max_delay: float | None = None
7474
) -> None:
7575
"""Cancels the given task and waits for it to complete.

packages/common-library/tests/test_async_tools.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import pytest
88
from common_library.async_tools import (
9-
cancel_and_wait,
9+
cancel_and_shielded_wait,
1010
delayed_start,
1111
make_async,
1212
maybe_await,
@@ -121,7 +121,7 @@ async def coro():
121121
await asyncio.sleep(0.1) # Let coro start
122122

123123
start = time.time()
124-
await cancel_and_wait(task)
124+
await cancel_and_shielded_wait(task)
125125

126126
elapsed = time.time() - start
127127
assert elapsed < SLEEP_TIME, "Task should be cancelled quickly"
@@ -149,7 +149,7 @@ async def coro():
149149

150150
async def outer_coro():
151151
try:
152-
await cancel_and_wait(inner_task)
152+
await cancel_and_shielded_wait(inner_task)
153153
except asyncio.CancelledError:
154154
assert (
155155
not inner_task.cancelled()
@@ -194,7 +194,7 @@ async def slow_cleanup_coro():
194194

195195
# Cancel with a max_delay shorter than cleanup time
196196
with pytest.raises(TimeoutError):
197-
await cancel_and_wait(
197+
await cancel_and_shielded_wait(
198198
task, max_delay=CLEANUP_TIME / 10
199199
) # 0.2 seconds < 2 seconds cleanup
200200

packages/service-library/src/servicelib/background_task.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from collections.abc import AsyncIterator, Awaitable, Callable, Coroutine
77
from typing import Any, Final, ParamSpec, TypeVar
88

9-
from common_library.async_tools import cancel_and_wait, delayed_start
9+
from common_library.async_tools import cancel_and_shielded_wait, delayed_start
1010
from tenacity import TryAgain, before_sleep_log, retry, retry_if_exception_type
1111
from tenacity.wait import wait_fixed
1212

@@ -142,4 +142,4 @@ async def periodic_task(
142142
if asyncio_task is not None:
143143
# NOTE: this stopping is shielded to prevent the cancellation to propagate
144144
# into the stopping procedure
145-
await asyncio.shield(cancel_and_wait(asyncio_task, max_delay=stop_timeout))
145+
await cancel_and_shielded_wait(asyncio_task, max_delay=stop_timeout)

packages/service-library/src/servicelib/long_running_tasks/task.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing import Any, Final, Protocol, TypeAlias
1010
from uuid import uuid4
1111

12-
from common_library.async_tools import cancel_and_wait
12+
from common_library.async_tools import cancel_and_shielded_wait
1313
from models_library.api_schemas_long_running_tasks.base import TaskProgress
1414
from pydantic import PositiveFloat
1515
from servicelib.background_task import create_periodic_task
@@ -105,7 +105,7 @@ async def teardown(self) -> None:
105105

106106
if self._stale_tasks_monitor_task:
107107
with log_catch(_logger, reraise=False):
108-
await cancel_and_wait(
108+
await cancel_and_shielded_wait(
109109
self._stale_tasks_monitor_task, max_delay=_CANCEL_TASK_TIMEOUT
110110
)
111111

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
import redis.asyncio as aioredis
1010
import redis.exceptions
11+
from common_library.async_tools import cancel_and_shielded_wait
1112
from redis.asyncio.lock import Lock
1213
from redis.asyncio.retry import Retry
1314
from redis.backoff import ExponentialBackoff
1415

15-
from ..async_utils import cancel_and_wait
1616
from ..background_task import periodic
1717
from ..logging_utils import log_catch, log_context
1818
from ._constants import (
@@ -88,7 +88,7 @@ async def shutdown(self) -> None:
8888
assert self._health_check_task_started_event # nosec
8989
# NOTE: wait for the health check task to have started once before we can cancel it
9090
await self._health_check_task_started_event.wait()
91-
await cancel_and_wait(
91+
await cancel_and_shielded_wait(
9292
self._health_check_task, max_delay=_HEALTHCHECK_TASK_TIMEOUT_S
9393
)
9494

packages/service-library/tests/rabbitmq/test_rabbitmq_rpc_interfaces_async_jobs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from dataclasses import dataclass, field
55

66
import pytest
7-
from common_library.async_tools import cancel_and_wait
7+
from common_library.async_tools import cancel_and_shielded_wait
88
from faker import Faker
99
from models_library.api_schemas_rpc_async_jobs.async_jobs import (
1010
AsyncJobGet,
@@ -137,7 +137,7 @@ async def setup(self) -> None:
137137
yield
138138

139139
for task in fake_server.tasks:
140-
await cancel_and_wait(task)
140+
await cancel_and_shielded_wait(task)
141141

142142

143143
@pytest.mark.parametrize("method", ["result", "status", "cancel"])

packages/service-library/tests/redis/test_project_lock.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from uuid import UUID
1111

1212
import pytest
13-
from common_library.async_tools import cancel_and_wait
13+
from common_library.async_tools import cancel_and_shielded_wait
1414
from faker import Faker
1515
from models_library.projects import ProjectID
1616
from models_library.projects_access import Owner
@@ -141,4 +141,4 @@ async def _locked_fct() -> None:
141141
with pytest.raises(ProjectLockError):
142142
await _locked_fct()
143143

144-
await cancel_and_wait(task1)
144+
await cancel_and_shielded_wait(task1)

packages/service-library/tests/test_background_task.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from unittest.mock import AsyncMock
1414

1515
import pytest
16-
from common_library.async_tools import cancel_and_wait
16+
from common_library.async_tools import cancel_and_shielded_wait
1717
from faker import Faker
1818
from pytest_mock.plugin import MockerFixture
1919
from servicelib.background_task import create_periodic_task, periodic, periodic_task
@@ -78,7 +78,10 @@ async def _creator(
7878
yield _creator
7979
# cleanup
8080
await asyncio.gather(
81-
*(cancel_and_wait(t, max_delay=stop_task_timeout) for t in created_tasks)
81+
*(
82+
cancel_and_shielded_wait(t, max_delay=stop_task_timeout)
83+
for t in created_tasks
84+
)
8285
)
8386

8487

packages/service-library/tests/test_background_task_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import arrow
1515
import pytest
16-
from common_library.async_tools import cancel_and_wait
16+
from common_library.async_tools import cancel_and_shielded_wait
1717
from servicelib.background_task_utils import exclusive_periodic
1818
from servicelib.redis import RedisClientSDK
1919
from settings_library.redis import RedisDatabase
@@ -71,7 +71,7 @@ async def _sleep_task(sleep_interval: float, on_sleep_events: mock.Mock) -> None
7171

7272
await _assert_on_sleep_done(sleep_events, stop_after=stop_after)
7373

74-
await cancel_and_wait(task, max_delay=5)
74+
await cancel_and_shielded_wait(task, max_delay=5)
7575

7676
events_timestamps: tuple[float, ...] = tuple(
7777
x.args[0].timestamp() for x in sleep_events.call_args_list

0 commit comments

Comments
 (0)