33from uuid import UUID
44
55from fastapi import FastAPI
6+ from models_library .api_schemas_directorv2 .computations import (
7+ ComputationGet as DirectorV2ComputationGet ,
8+ )
69from models_library .projects_nodes_io import NodeID
710from models_library .projects_pipeline import ComputationTask
811from models_library .projects_state import RunningState
2124logger = logging .getLogger (__name__ )
2225
2326
24- # API MODELS ---------------------------------------------
25- # NOTE: as services/director-v2/src/simcore_service_director_v2/models/schemas/comp_tasks.py
26-
27-
2827class ComputationTaskGet (ComputationTask ):
2928 url : AnyHttpUrl = Field (
3029 ..., description = "the link where to get the status of the task"
@@ -66,12 +65,16 @@ class TaskLogFileGet(BaseModel):
6665
6766# API CLASS ---------------------------------------------
6867
69- _exception_mapper = partial (service_exception_mapper , service_name = "Director V2" )
68+ _client_status_code_to_exception = partial (
69+ service_exception_mapper , service_name = "Director V2"
70+ )
7071
7172
7273class DirectorV2Api (BaseServiceClientApi ):
7374
74- @_exception_mapper (http_status_map = {status .HTTP_404_NOT_FOUND : JobNotFoundError })
75+ @_client_status_code_to_exception (
76+ http_status_map = {status .HTTP_404_NOT_FOUND : JobNotFoundError }
77+ )
7578 async def get_computation (
7679 self , * , project_id : UUID , user_id : PositiveInt
7780 ) -> ComputationTaskGet :
@@ -82,25 +85,29 @@ async def get_computation(
8285 },
8386 )
8487 response .raise_for_status ()
85- task : ComputationTaskGet = ComputationTaskGet .model_validate_json (response .text )
86- return task
88+ return ComputationTaskGet .model_validate (
89+ DirectorV2ComputationGet .model_validate_json (response .text ),
90+ from_attributes = True ,
91+ )
8792
88- @_exception_mapper ( http_status_map = { status . HTTP_404_NOT_FOUND : JobNotFoundError })
89- async def stop_computation (
90- self , * , project_id : UUID , user_id : PositiveInt
91- ) -> ComputationTaskGet :
93+ @_client_status_code_to_exception (
94+ http_status_map = { status . HTTP_404_NOT_FOUND : JobNotFoundError }
95+ )
96+ async def stop_computation ( self , * , project_id : UUID , user_id : PositiveInt ) -> None :
9297 response = await self .client .post (
9398 f"/v2/computations/{ project_id } :stop" ,
9499 json = {
95100 "user_id" : user_id ,
96101 },
97102 )
98103 response .raise_for_status ()
99- task : ComputationTaskGet = ComputationTaskGet .model_validate_json (response .text )
100- return task
101104
102- @_exception_mapper (http_status_map = {status .HTTP_404_NOT_FOUND : JobNotFoundError })
103- async def delete_computation (self , * , project_id : UUID , user_id : PositiveInt ):
105+ @_client_status_code_to_exception (
106+ http_status_map = {status .HTTP_404_NOT_FOUND : JobNotFoundError }
107+ )
108+ async def delete_computation (
109+ self , * , project_id : UUID , user_id : PositiveInt
110+ ) -> None :
104111 response = await self .client .request (
105112 "DELETE" ,
106113 f"/v2/computations/{ project_id } " ,
@@ -111,7 +118,7 @@ async def delete_computation(self, *, project_id: UUID, user_id: PositiveInt):
111118 )
112119 response .raise_for_status ()
113120
114- @_exception_mapper (
121+ @_client_status_code_to_exception (
115122 http_status_map = {status .HTTP_404_NOT_FOUND : LogFileNotFoundError }
116123 )
117124 async def get_computation_logs (
0 commit comments