Skip to content

Commit

Permalink
first attempt at get_job_pricing_unit
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgaard-itis committed Oct 11, 2023
1 parent 0901949 commit 9189796
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 -------------------------------------------------------------

Expand Down

0 comments on commit 9189796

Please sign in to comment.