|
4 | 4 | import time |
5 | 5 | from datetime import UTC, datetime, timedelta |
6 | 6 | from functools import cached_property |
7 | | -from typing import TYPE_CHECKING, Any |
| 7 | +from typing import TYPE_CHECKING, Any, get_args |
8 | 8 |
|
9 | | -from apify_client._consts import DEFAULT_WAIT_FOR_FINISH, DEFAULT_WAIT_WHEN_JOB_NOT_EXIST, TERMINAL_STATUSES |
| 9 | +from apify_client._consts import DEFAULT_WAIT_FOR_FINISH, DEFAULT_WAIT_WHEN_JOB_NOT_EXIST |
10 | 10 | from apify_client._docs import docs_group |
| 11 | +from apify_client._literals import TerminalActorJobStatus |
11 | 12 | from apify_client._logging import WithLogDetailsClient |
12 | 13 | from apify_client._models import ActorJobResponse |
13 | 14 | from apify_client._utils import ( |
|
24 | 25 | from apify_client._http_clients import HttpClient, HttpClientAsync |
25 | 26 | from apify_client._literals import Timeout |
26 | 27 |
|
| 28 | +_TERMINAL_STATUSES: frozenset[TerminalActorJobStatus] = frozenset(get_args(TerminalActorJobStatus)) |
| 29 | + |
27 | 30 |
|
28 | 31 | class ResourceClientBase(metaclass=WithLogDetailsClient): |
29 | 32 | """Base class with shared implementation for sync and async resource clients. |
@@ -333,7 +336,7 @@ def _wait_for_finish( |
333 | 336 | # Reset the not-found streak so a later transient 404 gets its own grace window. |
334 | 337 | not_found_deadline = None |
335 | 338 |
|
336 | | - is_terminal = actor_job_response.data.status in TERMINAL_STATUSES |
| 339 | + is_terminal = actor_job_response.data.status in _TERMINAL_STATUSES |
337 | 340 | is_timed_out = deadline is not None and datetime.now(UTC) >= deadline |
338 | 341 |
|
339 | 342 | if is_terminal or is_timed_out: |
@@ -526,7 +529,7 @@ async def _wait_for_finish( |
526 | 529 | # Reset the not-found streak so a later transient 404 gets its own grace window. |
527 | 530 | not_found_deadline = None |
528 | 531 |
|
529 | | - is_terminal = actor_job_response.data.status in TERMINAL_STATUSES |
| 532 | + is_terminal = actor_job_response.data.status in _TERMINAL_STATUSES |
530 | 533 | is_timed_out = deadline is not None and datetime.now(UTC) >= deadline |
531 | 534 |
|
532 | 535 | if is_terminal or is_timed_out: |
|
0 commit comments