diff --git a/services/api-server/src/simcore_service_api_server/api/routes/solvers_jobs.py b/services/api-server/src/simcore_service_api_server/api/routes/solvers_jobs.py index 25fe5e94db3..408be42686c 100644 --- a/services/api-server/src/simcore_service_api_server/api/routes/solvers_jobs.py +++ b/services/api-server/src/simcore_service_api_server/api/routes/solvers_jobs.py @@ -11,6 +11,7 @@ from fastapi.responses import RedirectResponse from fastapi_pagination.api import create_page from models_library.api_schemas_webserver.projects import ProjectCreateNew, ProjectGet +from models_library.api_schemas_webserver.resource_usage import PricingUnitGet from models_library.api_schemas_webserver.wallets import WalletGet from models_library.clusters import ClusterID from models_library.projects_nodes_io import BaseFileLink @@ -559,3 +560,27 @@ async def get_job_wallet( f"Cannot find job={job_name}", status_code=status.HTTP_404_NOT_FOUND, ) + + +@router.get( + "/{solver_key:path}/releases/{version}/jobs/{job_id:uuid}/pricing_unit", + response_model=PricingUnitGet | None, + responses={**_COMMON_ERROR_RESPONSES}, + include_in_schema=API_SERVER_DEV_FEATURES_ENABLED, +) +async def get_job_pricing_unit( + solver_key: SolverKeyId, + version: VersionStr, + job_id: JobID, + webserver_api: Annotated[AuthSession, Depends(get_webserver_session)], +): + job_name = _compose_job_resource_name(solver_key, version, job_id) + _logger.debug("Getting wallet for job '%s'", job_name) + + project: ProjectGet = await webserver_api.get_project(project_id=job_id) + node_ids = list(project.workbench.keys()) + assert len(node_ids) == 1 # nosec + node_id: UUID = UUID(node_ids[0]) + return await webserver_api.get_project_node_pricing_unit( + project_id=job_id, node_id=node_id + ) diff --git a/services/api-server/src/simcore_service_api_server/services/webserver.py b/services/api-server/src/simcore_service_api_server/services/webserver.py index 5860068ba5e..e1923465513 100644 --- a/services/api-server/src/simcore_service_api_server/services/webserver.py +++ b/services/api-server/src/simcore_service_api_server/services/webserver.py @@ -15,6 +15,7 @@ ProjectMetadataGet, ProjectMetadataUpdate, ) +from models_library.api_schemas_webserver.resource_usage import PricingUnitGet from models_library.api_schemas_webserver.wallets import WalletGet from models_library.generics import Envelope from models_library.projects import ProjectID @@ -392,6 +393,20 @@ async def get_wallet(self, wallet_id: int) -> WalletGet: assert data # nosec return data + async def get_project_node_pricing_unit( + self, project_id: UUID, node_id: UUID + ) -> PricingUnitGet: + response = await self.client.get( + f"/projects/{project_id}/nodes/{node_id}/pricing-unit", + cookies=self.session_cookies, + ) + + data = self._get_data_or_raise( + response, + {status.HTTP_404_NOT_FOUND: ProjectNotFoundError(project_id=project_id)}, + ) + return PricingUnitGet.parse_obj(data) + # MODULES APP SETUP -------------------------------------------------------------