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
10 changes: 10 additions & 0 deletions docs/sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,16 @@ class SandboxTimeoutError(SandboxError)

Raised when a sandbox operation times out

<a id="koyeb/sandbox.utils.SandboxDeploymentError"></a>

## SandboxDeploymentError Objects

```python
class SandboxDeploymentError(SandboxError)
```

Raised when a sandbox deployment reaches an error state

<a id="koyeb/sandbox.executor_client"></a>

# koyeb/sandbox.executor\_client
Expand Down
3 changes: 2 additions & 1 deletion koyeb/sandbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
)
from .filesystem import FileInfo, SandboxFilesystem
from .sandbox import AsyncSandbox, ExposedPort, ProcessInfo, Sandbox
from .utils import SandboxError, SandboxTimeoutError
from .utils import SandboxDeploymentError, SandboxError, SandboxTimeoutError

__all__ = [
"Sandbox",
Expand All @@ -27,6 +27,7 @@
"AsyncSandboxExecutor",
"FileInfo",
"SandboxStatus",
"SandboxDeploymentError",
"SandboxError",
"SandboxTimeoutError",
"CommandResult",
Expand Down
16 changes: 16 additions & 0 deletions koyeb/sandbox/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from .utils import (
DEFAULT_INSTANCE_WAIT_TIMEOUT,
DEFAULT_POLL_INTERVAL,
SandboxDeploymentError,
SandboxError,
SandboxTimeoutError,
async_wrapper,
Expand Down Expand Up @@ -388,12 +389,20 @@ def get_from_id(
sandbox_secret=sandbox_secret,
)

_DEPLOYMENT_ERROR_STATUSES = {
DeploymentStatus.ERROR,
DeploymentStatus.ERRORING,
}

def _is_deployment_healthy(self) -> bool:
"""
Check if the sandbox deployment status is HEALTHY via the API.

Returns:
bool: True if the deployment status is HEALTHY, False otherwise

Raises:
SandboxDeploymentError: If the deployment has reached a terminal error state
"""
try:
_, services_api, _, _, deployments_api = get_api_client(self.api_token)
Expand All @@ -404,7 +413,14 @@ def _is_deployment_healthy(self) -> bool:
return False
deployment_response = deployments_api.get_deployment(deployment_id)
status = deployment_response.deployment.status
if status in self._DEPLOYMENT_ERROR_STATUSES:
raise SandboxDeploymentError(
f"Sandbox '{self.name}' deployment reached status {status.value}. "
f"The sandbox will not become ready."
)
return status == DeploymentStatus.HEALTHY
except SandboxDeploymentError:
raise
except Exception:
return False

Expand Down
4 changes: 4 additions & 0 deletions koyeb/sandbox/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,7 @@ class SandboxError(Exception):

class SandboxTimeoutError(SandboxError):
"""Raised when a sandbox operation times out"""


class SandboxDeploymentError(SandboxError):
"""Raised when a sandbox deployment reaches an error state"""
Loading