Skip to content

Commit 01be053

Browse files
author
Andrei Neagu
committed
refactor
1 parent 501a672 commit 01be053

File tree

1 file changed

+8
-10
lines changed
  • packages/service-library/src/servicelib/long_running_tasks

1 file changed

+8
-10
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
from settings_library.redis import RedisDatabase, RedisSettings
1515
from tenacity import (
1616
AsyncRetrying,
17-
TryAgain,
18-
retry_if_exception_type,
17+
retry_unless_exception_type,
1918
stop_after_delay,
2019
wait_exponential,
2120
)
@@ -458,17 +457,16 @@ async def remove_task(
458457

459458
# wait for task to be removed since it might not have been running
460459
# in this process
461-
async for attempt in AsyncRetrying(
462-
wait=wait_exponential(max=1),
463-
stop=stop_after_delay(_TASK_REMOVAL_MAX_WAIT),
464-
retry=retry_if_exception_type(TryAgain),
465-
):
466-
with attempt: # noqa: SIM117
467-
with suppress(TaskNotFoundError):
460+
with suppress(TaskNotFoundError):
461+
async for attempt in AsyncRetrying(
462+
wait=wait_exponential(max=1),
463+
stop=stop_after_delay(_TASK_REMOVAL_MAX_WAIT),
464+
retry=retry_unless_exception_type(TaskNotFoundError),
465+
):
466+
with attempt:
468467
await self._get_tracked_task(
469468
tracked_task.task_id, tracked_task.task_context
470469
)
471-
raise TryAgain
472470

473471
def _get_task_id(self, task_name: str, *, is_unique: bool) -> TaskId:
474472
suffix = "unique" if is_unique else f"{uuid4()}"

0 commit comments

Comments
 (0)