Skip to content

Commit 651f188

Browse files
committed
Address feedback
1 parent 3f7145e commit 651f188

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tests/integration/_utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4-
from typing import TYPE_CHECKING, TypeVar, cast
4+
from typing import TYPE_CHECKING, TypeVar
55

66
from crawlee._utils.crypto import crypto_random_object_id
77

@@ -13,22 +13,26 @@
1313
T = TypeVar('T')
1414

1515

16-
async def call_with_exp_backoff(fn: Callable[[], Awaitable[T]], *, max_retries: int = 3) -> T:
16+
async def call_with_exp_backoff(fn: Callable[[], Awaitable[T]], *, max_retries: int = 3) -> T | None:
1717
"""Call an async callable with exponential backoff retries until it returns a truthy value.
1818
1919
In shared request queue mode, there is a propagation delay before newly added, reclaimed, or handled requests
2020
become visible in the API (see https://github.com/apify/apify-sdk-python/issues/808). This helper retries with
2121
exponential backoff to handle that delay in integration tests.
2222
"""
2323
result = None
24+
2425
for attempt in range(max_retries):
2526
result = await fn()
27+
2628
if result:
2729
return result
30+
2831
delay = 2**attempt
2932
Actor.log.info(f'{fn} returned {result!r}, retrying in {delay}s (attempt {attempt + 1}/{max_retries})')
3033
await asyncio.sleep(delay)
31-
return cast('T', result)
34+
35+
return result
3236

3337

3438
def generate_unique_resource_name(label: str) -> str:

0 commit comments

Comments
 (0)