Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

## [1.7.1](../../releases/tag/v1.7.1) - Unreleased

...
### Fixed

- fix breaking change (sync -> async) in 1.7.0
- fix getting storages of last run

## [1.7.0](../../releases/tag/v1.7.0) - 2024-05-20

Expand Down
48 changes: 3 additions & 45 deletions src/apify_client/clients/resource_clients/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,7 @@ def last_run(
Returns:
RunClient: The resource client for the last run of this actor.
"""
# Note:
# The API does not provide a direct endpoint for aborting the last Actor run using a URL like:
# https://api.apify.com/v2/acts/{actor_id}/runs/last/abort
# To achieve this, we need to implement a workaround using the following URL format:
# https://api.apify.com/v2/acts/{actorId}/runs/{runId}/abort

last_run_client = RunClient(
return RunClient(
**self._sub_resource_init_options(
resource_id='last',
resource_path='runs',
Expand All @@ -361,21 +355,6 @@ def last_run(
)
)

last_run_client_info = last_run_client.get()
actor_id = last_run_client_info['actId'] # type: ignore
actor_run_id = last_run_client_info['id'] # type: ignore

return RunClient(
**self._sub_resource_init_options(
base_url='https://api.apify.com/v2',
resource_path=f'acts/{actor_id}/runs/{actor_run_id}',
params=self._params(
status=maybe_extract_enum_member_value(status),
origin=maybe_extract_enum_member_value(origin),
),
)
)

def versions(self: ActorClient) -> ActorVersionCollectionClient:
"""Retrieve a client for the versions of this actor."""
return ActorVersionCollectionClient(**self._sub_resource_init_options())
Expand Down Expand Up @@ -655,7 +634,7 @@ def runs(self: ActorClientAsync) -> RunCollectionClientAsync:
"""Retrieve a client for the runs of this actor."""
return RunCollectionClientAsync(**self._sub_resource_init_options(resource_path='runs'))

async def last_run(self: ActorClientAsync, *, status: ActorJobStatus | None = None, origin: MetaOrigin | None = None) -> RunClientAsync:
def last_run(self: ActorClientAsync, *, status: ActorJobStatus | None = None, origin: MetaOrigin | None = None) -> RunClientAsync:
"""Retrieve the client for the last run of this actor.

Last run is retrieved based on the start time of the runs.
Expand All @@ -667,13 +646,7 @@ async def last_run(self: ActorClientAsync, *, status: ActorJobStatus | None = No
Returns:
RunClientAsync: The resource client for the last run of this actor.
"""
# Note:
# The API does not provide a direct endpoint for aborting the last Actor run using a URL like:
# https://api.apify.com/v2/acts/{actor_id}/runs/last/abort
# To achieve this, we need to implement a workaround using the following URL format:
# https://api.apify.com/v2/acts/{actorId}/runs/{runId}/abort

last_run_client = RunClientAsync(
return RunClientAsync(
**self._sub_resource_init_options(
resource_id='last',
resource_path='runs',
Expand All @@ -684,21 +657,6 @@ async def last_run(self: ActorClientAsync, *, status: ActorJobStatus | None = No
)
)

last_run_client_info = await last_run_client.get()
actor_id = last_run_client_info['actId'] # type: ignore
actor_run_id = last_run_client_info['id'] # type: ignore

return RunClientAsync(
**self._sub_resource_init_options(
base_url='https://api.apify.com/v2',
resource_path=f'acts/{actor_id}/runs/{actor_run_id}',
params=self._params(
status=maybe_extract_enum_member_value(status),
origin=maybe_extract_enum_member_value(origin),
),
)
)

def versions(self: ActorClientAsync) -> ActorVersionCollectionClientAsync:
"""Retrieve a client for the versions of this actor."""
return ActorVersionCollectionClientAsync(**self._sub_resource_init_options())
Expand Down
48 changes: 3 additions & 45 deletions src/apify_client/clients/resource_clients/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,7 @@ def last_run(self: TaskClient, *, status: ActorJobStatus | None = None, origin:
Returns:
RunClient: The resource client for the last run of this task.
"""
# Note:
# The API does not provide a direct endpoint for aborting the last task run using a URL like:
# https://api.apify.com/v2/actor-tasks/{task_id}/runs/last/abort
# To achieve this, we need to implement a workaround using the following URL format:
# https://api.apify.com/v2/acts/{actorId}/runs/{runId}/abort

last_run_client = RunClient(
return RunClient(
**self._sub_resource_init_options(
resource_id='last',
resource_path='runs',
Expand All @@ -283,21 +277,6 @@ def last_run(self: TaskClient, *, status: ActorJobStatus | None = None, origin:
)
)

last_run_client_info = last_run_client.get()
actor_id = last_run_client_info['actId'] # type: ignore
actor_run_id = last_run_client_info['id'] # type: ignore

return RunClient(
**self._sub_resource_init_options(
base_url='https://api.apify.com/v2',
resource_path=f'acts/{actor_id}/runs/{actor_run_id}',
params=self._params(
status=maybe_extract_enum_member_value(status),
origin=maybe_extract_enum_member_value(origin),
),
)
)

def webhooks(self: TaskClient) -> WebhookCollectionClient:
"""Retrieve a client for webhooks associated with this task."""
return WebhookCollectionClient(**self._sub_resource_init_options())
Expand Down Expand Up @@ -512,7 +491,7 @@ def runs(self: TaskClientAsync) -> RunCollectionClientAsync:
"""Retrieve a client for the runs of this task."""
return RunCollectionClientAsync(**self._sub_resource_init_options(resource_path='runs'))

async def last_run(self: TaskClientAsync, *, status: ActorJobStatus | None = None, origin: MetaOrigin | None = None) -> RunClientAsync:
def last_run(self: TaskClientAsync, *, status: ActorJobStatus | None = None, origin: MetaOrigin | None = None) -> RunClientAsync:
"""Retrieve the client for the last run of this task.

Last run is retrieved based on the start time of the runs.
Expand All @@ -524,13 +503,7 @@ async def last_run(self: TaskClientAsync, *, status: ActorJobStatus | None = Non
Returns:
RunClientAsync: The resource client for the last run of this task.
"""
# Note:
# The API does not provide a direct endpoint for aborting the last task run using a URL like:
# https://api.apify.com/v2/actor-tasks/{task_id}/runs/last/abort
# To achieve this, we need to implement a workaround using the following URL format:
# https://api.apify.com/v2/acts/{actorId}/runs/{runId}/abort

last_run_client = RunClientAsync(
return RunClientAsync(
**self._sub_resource_init_options(
resource_id='last',
resource_path='runs',
Expand All @@ -541,21 +514,6 @@ async def last_run(self: TaskClientAsync, *, status: ActorJobStatus | None = Non
)
)

last_run_client_info = await last_run_client.get()
actor_id = last_run_client_info['actId'] # type: ignore
actor_run_id = last_run_client_info['id'] # type: ignore

return RunClientAsync(
**self._sub_resource_init_options(
base_url='https://api.apify.com/v2',
resource_path=f'acts/{actor_id}/runs/{actor_run_id}',
params=self._params(
status=maybe_extract_enum_member_value(status),
origin=maybe_extract_enum_member_value(origin),
),
)
)

def webhooks(self: TaskClientAsync) -> WebhookCollectionClientAsync:
"""Retrieve a client for webhooks associated with this task."""
return WebhookCollectionClientAsync(**self._sub_resource_init_options())