|
13 | 13 | from pydantic import AliasChoices |
14 | 14 |
|
15 | 15 | from apify_client import ApifyClientAsync |
16 | | -from apify_client._consts import ( |
17 | | - DEFAULT_MAX_RETRIES, |
18 | | - DEFAULT_MIN_DELAY_BETWEEN_RETRIES, |
19 | | - DEFAULT_TIMEOUT_LONG, |
20 | | - DEFAULT_TIMEOUT_MAX, |
21 | | - DEFAULT_TIMEOUT_MEDIUM, |
22 | | - DEFAULT_TIMEOUT_SHORT, |
23 | | -) |
24 | 16 | from crawlee import service_locator |
25 | 17 | from crawlee.errors import ServiceConflictError |
26 | 18 | from crawlee.events import ( |
@@ -516,20 +508,28 @@ def new_client( |
516 | 508 | timeout: Baseline HTTP timeout for medium-duration API operations. The underlying client uses |
517 | 509 | separate timeout tiers for short/medium/long/max-duration calls; passing a value here scales |
518 | 510 | all four tiers proportionally (short = `timeout / 6`, long = `timeout * 12`, |
519 | | - max = `timeout * 24`). |
| 511 | + max = `timeout * 12`). |
520 | 512 | """ |
521 | | - return ApifyClientAsync( |
522 | | - token=token or self.configuration.token, |
523 | | - api_url=api_url or self.configuration.api_base_url, |
524 | | - max_retries=max_retries if max_retries is not None else DEFAULT_MAX_RETRIES, |
525 | | - min_delay_between_retries=min_delay_between_retries |
526 | | - if min_delay_between_retries is not None |
527 | | - else DEFAULT_MIN_DELAY_BETWEEN_RETRIES, |
528 | | - timeout_short=timeout / 6 if timeout is not None else DEFAULT_TIMEOUT_SHORT, |
529 | | - timeout_medium=timeout if timeout is not None else DEFAULT_TIMEOUT_MEDIUM, |
530 | | - timeout_long=timeout * 12 if timeout is not None else DEFAULT_TIMEOUT_LONG, |
531 | | - timeout_max=timeout * 24 if timeout is not None else DEFAULT_TIMEOUT_MAX, |
532 | | - ) |
| 513 | + # Forward only the explicitly provided options; omitting the rest lets `ApifyClientAsync` apply its |
| 514 | + # own defaults, so the SDK doesn't have to import and re-pass the client's private default constants. |
| 515 | + client_kwargs: dict[str, Any] = { |
| 516 | + 'token': token or self.configuration.token, |
| 517 | + 'api_url': api_url or self.configuration.api_base_url, |
| 518 | + } |
| 519 | + if max_retries is not None: |
| 520 | + client_kwargs['max_retries'] = max_retries |
| 521 | + if min_delay_between_retries is not None: |
| 522 | + client_kwargs['min_delay_between_retries'] = min_delay_between_retries |
| 523 | + if timeout is not None: |
| 524 | + # `apify-client` v3 splits the timeout into four tiers; scale them from the single baseline, |
| 525 | + # mirroring the client's default ratios (medium = baseline, short = baseline / 6, |
| 526 | + # long = max = baseline * 12). |
| 527 | + client_kwargs['timeout_short'] = timeout / 6 |
| 528 | + client_kwargs['timeout_medium'] = timeout |
| 529 | + client_kwargs['timeout_long'] = timeout * 12 |
| 530 | + client_kwargs['timeout_max'] = timeout * 12 |
| 531 | + |
| 532 | + return ApifyClientAsync(**client_kwargs) |
533 | 533 |
|
534 | 534 | @_ensure_context |
535 | 535 | async def open_dataset( |
@@ -998,7 +998,7 @@ async def call( |
998 | 998 | webhooks: list[Webhook] | None = None, |
999 | 999 | wait: timedelta | None = None, |
1000 | 1000 | logger: logging.Logger | None | Literal['default'] = 'default', |
1001 | | - ) -> Run | None: |
| 1001 | + ) -> Run: |
1002 | 1002 | """Start an Actor on the Apify Platform and wait for it to finish before returning. |
1003 | 1003 |
|
1004 | 1004 | It waits indefinitely, unless the wait argument is provided. |
@@ -1076,7 +1076,7 @@ async def call_task( |
1076 | 1076 | webhooks: list[Webhook] | None = None, |
1077 | 1077 | wait: timedelta | None = None, |
1078 | 1078 | token: str | None = None, |
1079 | | - ) -> Run | None: |
| 1079 | + ) -> Run: |
1080 | 1080 | """Start an Actor task on the Apify Platform and wait for it to finish before returning. |
1081 | 1081 |
|
1082 | 1082 | It waits indefinitely, unless the wait argument is provided. |
@@ -1260,9 +1260,6 @@ async def add_webhook(self, webhook: Webhook, *, idempotency_key: str | None = N |
1260 | 1260 | webhook: The webhook to be added. It is automatically bound to the current Actor run. |
1261 | 1261 | idempotency_key: Deprecated. Pass `idempotency_key` on the `Webhook` instance instead. |
1262 | 1262 | Will be removed in version 5.0.0. |
1263 | | -
|
1264 | | - Returns: |
1265 | | - The created webhook. |
1266 | 1263 | """ |
1267 | 1264 | if idempotency_key is not None: |
1268 | 1265 | warnings.warn( |
|
0 commit comments