Skip to content

Commit

Permalink
Views: Add logic for supporting default_job_type on workspace. Add lo…
Browse files Browse the repository at this point in the history
…gic for grabbing the default_job_type from the workspace if no job_type is passed when the job is launched.
  • Loading branch information
Juan Puerto committed Feb 14, 2024
1 parent 63de92e commit a3c7841
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/user_workspaces_server/views/workspace_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ def post(self, request):

workspace_details = body.get("workspace_details", {})

if default_job_type := body.get("default_job_type"):
if (
default_job_type
not in apps.get_app_config("user_workspaces_server").available_job_types
):
raise WorkspaceClientException(
f"{default_job_type} is not in the list of available job types."
)

if not isinstance(workspace_details, dict):
raise ParseError("Workspace details not JSON.")

Expand All @@ -75,6 +84,7 @@ def post(self, request):
"current_workspace_details": {"files": [], "symlinks": []},
},
"status": "idle",
"default_job_type": default_job_type,
}

main_storage = apps.get_app_config("user_workspaces_server").main_storage
Expand Down Expand Up @@ -193,8 +203,16 @@ def put(self, request, workspace_id, put_type=None):
except Exception as e:
raise ParseError(f"Invalid JSON: {str(e)}")

if "job_type" not in body:
raise ParseError("Missing job_type.")
if (job_type := body.get("job_type")) is None:
if not workspace.default_job_type:
raise ParseError("Missing job_type and no default job type set on workspace.")
else:
job_type = workspace.default_job_type

if job_type not in apps.get_app_config("user_workspaces_server").available_job_types:
raise WorkspaceClientException(
f"{job_type} is not in the list of available job types."
)

job_details = body.get("job_details", {})

Expand All @@ -209,7 +227,7 @@ def put(self, request, workspace_id, put_type=None):
job_data = {
"user_id": workspace.user_id,
"workspace_id": workspace,
"job_type": body["job_type"],
"job_type": job_type,
"datetime_created": datetime.now(),
"job_details": {
"metrics": {},
Expand All @@ -229,7 +247,7 @@ def put(self, request, workspace_id, put_type=None):
try:
job_type_config = apps.get_app_config(
"user_workspaces_server"
).available_job_types.get(body["job_type"])
).available_job_types.get(job_type)

job_to_launch = utils.generate_controller_object(
job_type_config["job_type"],
Expand Down

0 comments on commit a3c7841

Please sign in to comment.