Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wait_function #400

Merged
merged 2 commits into from
Feb 19, 2024
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
21 changes: 21 additions & 0 deletions references/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,27 @@ It is considered finished when the status is done, failed or cancelled.

- `exceptions.FutureTimeoutError`: The compute plan took more than the duration set in the timeout to complete.
Not raised when `timeout == None`
## wait_function
```text
wait_function(self, key: str, *, timeout: Optional[float] = None, polling_period: float = 1.0, raise_on_failure: bool = True) -> substra.sdk.models.Function
```

Wait for the build of the given function to finish.
It is considered finished when the status is ready, failed or cancelled.

**Arguments:**
- `key (str, required)`: the key of the task to wait for.
- `timeout (float, optional)`: maximum time to wait, in seconds. If set to None, will hang until completion.
- `polling_period (float, required)`: time to wait between two checks, in seconds. Defaults to 2.0.
- `raise_on_failure (bool, required)`: whether to raise an exception if the execution fails. Defaults to True.

**Returns:**

- `models.Function`: the function once built
Raises:
exceptions.FutureFailureError: The function build failed or have been cancelled.
exceptions.FutureTimeoutError: The function took more than the duration set in the timeout to build.
Not raised when `timeout == None`
## wait_task
```text
wait_task(self, key: str, *, timeout: Optional[float] = None, polling_period: float = 2.0, raise_on_failure: bool = True) -> substra.sdk.models.Task
Expand Down
1 change: 1 addition & 0 deletions references/sdk_models.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Asset creation specification base class.
- creation_date: <class 'datetime.datetime'>
- inputs: typing.List[substra.sdk.models.FunctionInput]
- outputs: typing.List[substra.sdk.models.FunctionOutput]
- status: <enum 'FunctionStatus'>
- description: <class 'substra.sdk.models._File'>
- archive: <class 'substra.sdk.models._File'>
```
Expand Down
14 changes: 9 additions & 5 deletions substra/sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ def wait_task(
@logit
def wait_function(
self, key: str, *, timeout: Optional[float] = None, polling_period: float = 1.0, raise_on_failure: bool = True
) -> models.Task:
) -> models.Function:
"""Wait for the build of the given function to finish.

It is considered finished when the status is ready, failed or cancelled.
Expand All @@ -1091,17 +1091,21 @@ def wait_function(
raise_on_failure (bool): whether to raise an exception if the execution fails. Defaults to True.

Returns:
models.Task: the task after completion
models.Function: the function once built

Raises:
exceptions.FutureFailureError: The task failed or have been cancelled.
exceptions.FutureTimeoutError: The task took more than the duration set in the timeout to complete.
exceptions.FutureFailureError: The function build failed or have been cancelled.
exceptions.FutureTimeoutError: The function took more than the duration set in the timeout to build.
Not raised when `timeout == None`
"""
asset_getter = self.get_function
status_canceled = models.FunctionStatus.canceled.value
status_failed = models.FunctionStatus.failed.value
statuses_stopped = (models.FunctionStatus.ready.value, models.FunctionStatus.canceled.value)
statuses_stopped = (
models.FunctionStatus.ready.value,
models.FunctionStatus.canceled.value,
models.FunctionStatus.failed.value,
)
return self._wait(
key=key,
asset_getter=asset_getter,
Expand Down
Loading