Skip to content

Commit 8a18479

Browse files
authored
Add the gracefully parameter to the "Abort run" method (#55)
The API now supports specifying this parameter, so I'm adding it to the client as well.
1 parent 6741a6a commit 8a18479

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Changelog
88

99
- replaced `base_url` with `api_url` in the client constructor
1010
to enable easier passing of the API server url from environment variables availabl to actors on the Apify platform
11+
- added the `gracefully` parameter to the "Abort run" method
1112

1213
### Internal changes
1314

docs/docs.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,12 +1020,18 @@ Return information about the actor run.
10201020

10211021
***
10221022

1023-
#### [](#runclient-abort) `RunClient.abort()`
1023+
#### [](#runclient-abort) `RunClient.abort(*, gracefully=None)`
10241024

10251025
Abort the actor run which is starting or currently running and return its details.
10261026

10271027
[https://docs.apify.com/api/v2#/reference/actor-runs/abort-run/abort-run](https://docs.apify.com/api/v2#/reference/actor-runs/abort-run/abort-run)
10281028

1029+
* **Parameters**
1030+
1031+
* **gracefully** (`bool`, *optional*) – If True, the actor run will abort gracefully.
1032+
It will send `aborting` and `persistStates` events into the run and force-stop the run after 30 seconds.
1033+
It is helpful in cases where you plan to resurrect the run later.
1034+
10291035
* **Returns**
10301036

10311037
The data of the aborted actor run

src/apify_client/clients/base/actor_job_base_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ def _wait_for_finish(self, wait_secs: Optional[int] = None) -> Optional[Dict]:
5959

6060
return job
6161

62-
def _abort(self) -> Dict:
62+
def _abort(self, gracefully: Optional[bool] = None) -> Dict:
6363
response = self.http_client.call(
6464
url=self._url('abort'),
6565
method='POST',
66-
params=self._params(),
66+
params=self._params(
67+
gracefully=gracefully,
68+
),
6769
)
6870
return _parse_date_fields(_pluck_data(response.json()))

src/apify_client/clients/resource_clients/run.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,20 @@ def get(self) -> Optional[Dict]:
2626
"""
2727
return self._get()
2828

29-
def abort(self) -> Dict:
29+
def abort(self, *, gracefully: Optional[bool] = None) -> Dict:
3030
"""Abort the actor run which is starting or currently running and return its details.
3131
3232
https://docs.apify.com/api/v2#/reference/actor-runs/abort-run/abort-run
3333
34+
Args:
35+
gracefully (bool, optional): If True, the actor run will abort gracefully.
36+
It will send ``aborting`` and ``persistStates`` events into the run and force-stop the run after 30 seconds.
37+
It is helpful in cases where you plan to resurrect the run later.
38+
3439
Returns:
3540
dict: The data of the aborted actor run
3641
"""
37-
return self._abort()
42+
return self._abort(gracefully=gracefully)
3843

3944
def wait_for_finish(self, *, wait_secs: Optional[int] = None) -> Optional[Dict]:
4045
"""Wait synchronously until the run finishes or the server times out.

0 commit comments

Comments
 (0)