Skip to content

Commit e593f95

Browse files
vdusekclaude
andcommitted
refactor: derive _TERMINAL_STATUSES from TerminalActorJobStatus literal
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b306913 commit e593f95

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

src/apify_client/_consts.py

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

33
from datetime import timedelta
4-
from typing import TYPE_CHECKING
5-
6-
if TYPE_CHECKING:
7-
from apify_client._literals import TerminalActorJobStatus
84

95
DEFAULT_API_URL = 'https://api.apify.com'
106
"""Default base URL for the Apify API."""
@@ -36,8 +32,5 @@
3632
DEFAULT_WAIT_WHEN_JOB_NOT_EXIST = timedelta(seconds=3)
3733
"""How long to wait for a job to exist before giving up."""
3834

39-
TERMINAL_STATUSES: frozenset[TerminalActorJobStatus] = frozenset({'SUCCEEDED', 'FAILED', 'TIMED-OUT', 'ABORTED'})
40-
"""Set of terminal Actor job statuses that indicate the job has finished."""
41-
4235
OVERRIDABLE_DEFAULT_HEADERS = {'Accept', 'Authorization', 'Accept-Encoding', 'User-Agent'}
4336
"""Headers that can be overridden by users, but will trigger a warning if they do so, as it may lead to API errors."""

src/apify_client/_resource_clients/_resource_client.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import time
55
from datetime import UTC, datetime, timedelta
66
from functools import cached_property
7-
from typing import TYPE_CHECKING, Any
7+
from typing import TYPE_CHECKING, Any, get_args
88

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
1010
from apify_client._docs import docs_group
11+
from apify_client._literals import TerminalActorJobStatus
1112
from apify_client._logging import WithLogDetailsClient
1213
from apify_client._models import ActorJobResponse
1314
from apify_client._utils import (
@@ -24,6 +25,8 @@
2425
from apify_client._http_clients import HttpClient, HttpClientAsync
2526
from apify_client._literals import Timeout
2627

28+
_TERMINAL_STATUSES: frozenset[TerminalActorJobStatus] = frozenset(get_args(TerminalActorJobStatus))
29+
2730

2831
class ResourceClientBase(metaclass=WithLogDetailsClient):
2932
"""Base class with shared implementation for sync and async resource clients.
@@ -333,7 +336,7 @@ def _wait_for_finish(
333336
# Reset the not-found streak so a later transient 404 gets its own grace window.
334337
not_found_deadline = None
335338

336-
is_terminal = actor_job_response.data.status in TERMINAL_STATUSES
339+
is_terminal = actor_job_response.data.status in _TERMINAL_STATUSES
337340
is_timed_out = deadline is not None and datetime.now(UTC) >= deadline
338341

339342
if is_terminal or is_timed_out:
@@ -526,7 +529,7 @@ async def _wait_for_finish(
526529
# Reset the not-found streak so a later transient 404 gets its own grace window.
527530
not_found_deadline = None
528531

529-
is_terminal = actor_job_response.data.status in TERMINAL_STATUSES
532+
is_terminal = actor_job_response.data.status in _TERMINAL_STATUSES
530533
is_timed_out = deadline is not None and datetime.now(UTC) >= deadline
531534

532535
if is_terminal or is_timed_out:

0 commit comments

Comments
 (0)