Skip to content
Snippets Groups Projects
Commit 5691f551 authored by Simon Künzel's avatar Simon Künzel
Browse files

Add job errors

parent b7fbed22
Branches
No related tags found
No related merge requests found
......@@ -8,6 +8,9 @@ class ApiError:
self.http_status_code = http_status_code
self.message = message
def __str__(self):
return f"ApiError[code={self.error_code}, status={self.http_status_code}, message='{self.message}']"
class ApiClientException(Exception):
......
......@@ -88,7 +88,7 @@ class CJsonObject(CJsonValue):
if optional and not self.has(key):
return None
if key not in self._data:
raise ApiClientException(ERROR_REQUEST_MISSING_PARAMETER(key))
raise ApiClientException(ERROR_REQUEST_MISSING_PARAMETER(f"{self._path}.{key}"))
return CJsonValue(self._data[key], f"{self._path}.{key}")
def get_object(self, key: str) -> "CJsonObject":
......
......@@ -9,8 +9,8 @@ from .user import User
class JobState(Enum):
READY = "ready"
SPAWNING = "spawning"
RUNNING = "running"
SPAWNING = "spawning" # Job is in K8s but wasn't scheduled yet
RUNNING = "running" # Job is running in K8s
FINISHED = "finished"
FINISHED_AND_PROCESSED = "finished_and_processed"
FAILED = "failed"
......@@ -22,6 +22,9 @@ _JOB_STATE_ENUM = create_enum_type(JobState)
class Job(ApiObject, Base):
ERROR_CODE_UNKNOWN_TYPE = "unknown_type"
ERROR_CODE_SPAWNING_FAILURE = "spawning_failure"
__table_args__ = (
CheckConstraint(
"(on_end_event_type IS NULL) = (on_end_event_data IS NULL)",
......@@ -127,3 +130,10 @@ class Job(ApiObject, Base):
},
cause_job_id=cause_job_id
)
def set_error(self, error_code: str, error_message: str or None = None):
self.status = JobState.FAILED
self.output_data = {
"error_code": error_code,
"error_message": error_message
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment