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

Special status for not running container #377

Merged
merged 1 commit into from
Apr 13, 2021
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
12 changes: 11 additions & 1 deletion platform_monitoring/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
json_response,
middleware,
)
from aiohttp.web_exceptions import HTTPNotFound
from aiohttp_security import check_authorized
from aiohttp_security.api import AUTZ_KEY
from neuro_auth_client import AuthClient, Permission
Expand All @@ -51,7 +52,13 @@
S3Config,
)
from .config_factory import EnvironConfigFactory
from .jobs_service import Container, ExecCreate, JobException, JobsService
from .jobs_service import (
Container,
ExecCreate,
JobException,
JobNotRunningException,
JobsService,
)
from .kube_client import JobError, KubeClient, KubeTelemetry
from .user import untrusted_user
from .utils import (
Expand Down Expand Up @@ -573,6 +580,9 @@ async def handle_exceptions(
except ValueError as e:
payload = {"error": str(e)}
return json_response(payload, status=HTTPBadRequest.status_code)
except JobNotRunningException as e:
payload = {"error": str(e)}
return json_response(payload, status=HTTPNotFound.status_code)
except JobException as e:
payload = {"error": str(e)}
return json_response(payload, status=HTTPBadRequest.status_code)
Expand Down
6 changes: 5 additions & 1 deletion platform_monitoring/jobs_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class JobException(Exception):
pass


class JobNotRunningException(JobException):
pass


class NodeNotFoundException(Exception):
def __init__(self, name: str) -> None:
super().__init__(f"Node {name!r} was not found")
Expand Down Expand Up @@ -131,7 +135,7 @@ async def attach(
while checks > 0:
data = await container.show()
if not data["State"]["Running"]:
raise JobException(f"Job '{job.id}' is not running.")
raise JobNotRunningException(f"Job '{job.id}' is not running.")
checks -= 1
if checks > 0:
await asyncio.sleep(0.5)
Expand Down