Skip to content

Commit

Permalink
reduce noise further
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgaard-itis committed Nov 7, 2024
1 parent 59213a0 commit 11cb8aa
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from datetime import datetime
from decimal import Decimal
from typing import Annotated

from pydantic import BaseModel, ConfigDict
from pydantic import BaseModel, ConfigDict, PlainSerializer

from ..projects import ProjectID
from ..projects_nodes_io import NodeID
Expand Down Expand Up @@ -49,7 +50,9 @@ class PricingUnitGet(OutputSchema):
pricing_unit_id: PricingUnitId
unit_name: str
unit_extra_info: dict
current_cost_per_unit: Decimal
current_cost_per_unit: Annotated[
Decimal, PlainSerializer(float, return_type=float, when_used="json")
]
default: bool


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
class WalletGet(OutputSchema):
wallet_id: WalletID
name: IDStr
description: str | None
description: str = None # TODO: should be nullable and default was added for backwards compatibility
owner: GroupID
thumbnail: str | None
thumbnail: str = None # TODO: should be nullable and default was added for backwards compatibility
status: WalletStatus
created: datetime
modified: datetime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@ async def create_job(
url_for: Annotated[Callable, Depends(get_reverse_url_mapper)],
product_name: Annotated[str, Depends(get_product_name)],
hidden: Annotated[bool, Query()] = True,
x_simcore_parent_project_uuid: Annotated[ProjectID | None, Header()] = None,
x_simcore_parent_node_id: Annotated[NodeID | None, Header()] = None,
x_simcore_parent_project_uuid: Annotated[
ProjectID, Header()
] = None, # TODO: should be nullable
x_simcore_parent_node_id: Annotated[
NodeID, Header()
] = None, # TODO: should be nullable
):
"""Creates a job in a specific release with given inputs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ async def get_job_custom_metadata(

@router.get(
"/{solver_key:path}/releases/{version}/jobs/{job_id:uuid}/wallet",
response_model=WalletGetWithAvailableCredits | None,
response_model=WalletGetWithAvailableCredits,
responses=WALLET_STATUS_CODES,
description=("Get job wallet\n\n" + FMSG_CHANGELOG_NEW_IN_VERSION.format("0.7")),
)
Expand All @@ -385,18 +385,18 @@ async def get_job_wallet(
version: VersionStr,
job_id: JobID,
webserver_api: Annotated[AuthSession, Depends(get_webserver_session)],
) -> WalletGetWithAvailableCredits | None:
) -> WalletGetWithAvailableCredits:
job_name = _compose_job_resource_name(solver_key, version, job_id)
_logger.debug("Getting wallet for job '%s'", job_name)

if project_wallet := await webserver_api.get_project_wallet(project_id=job_id):
return await webserver_api.get_wallet(wallet_id=project_wallet.wallet_id)
return None
raise MissingWalletError(job_id=job_id)


@router.get(
"/{solver_key:path}/releases/{version}/jobs/{job_id:uuid}/pricing_unit",
response_model=PricingUnitGet | None,
response_model=PricingUnitGet,
responses=_PRICING_UNITS_STATUS_CODES,
description=(
"Get job pricing unit\n\n" + FMSG_CHANGELOG_NEW_IN_VERSION.format("0.7")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@

# ArgumentTypes are types used in the job inputs (see ResultsTypes)
ArgumentTypes: TypeAlias = (
File | StrictFloat | StrictInt | StrictBool | str | list | None
)
File | StrictFloat | StrictInt | StrictBool | str | list
) # TODO: should be nullable
KeywordArguments: TypeAlias = dict[str, ArgumentTypes]
PositionalArguments: TypeAlias = list[ArgumentTypes]

Expand Down Expand Up @@ -152,7 +152,9 @@ class JobMetadata(BaseModel):
metadata: dict[str, MetaValueType] = Field(..., description="Custom key-value map")

# Links
url: HttpUrl | None = Field(..., description="Link to get this resource (self)")
url: HttpUrl = Field(
..., description="Link to get this resource (self)"
) # TODO: should be nullable

model_config = ConfigDict(
json_schema_extra={
Expand Down Expand Up @@ -198,13 +200,15 @@ class Job(BaseModel):
)

# Get links to other resources
url: HttpUrl | None = Field(..., description="Link to get this resource (self)")
runner_url: HttpUrl | None = Field(
url: HttpUrl = Field(
..., description="Link to get this resource (self)"
) # TODO: should be nullable
runner_url: HttpUrl = Field(
..., description="Link to the solver's job (parent collection)"
)
outputs_url: HttpUrl | None = Field(
) # TODO: should be nullable
outputs_url: HttpUrl = Field(
..., description="Link to the job outputs (sub-collection)"
)
) # TODO: should be nullable

model_config = ConfigDict(
json_schema_extra={
Expand Down Expand Up @@ -330,7 +334,7 @@ def create_from_headers(cls, headers: Headers) -> "JobPricingSpecification | Non

class JobLog(BaseModel):
job_id: ProjectID
node_id: NodeID | None = None
node_id: NodeID = None # TODO: should be nullable
log_level: LogLevelInt
messages: list[LogMessageStr]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ class Solver(BaseModel):

# Human readables Identifiers
title: str = Field(..., description="Human readable name")
description: str | None = None
description: str = None # TODO: should be nullable
maintainer: str
# TODO: consider released: Optional[datetime] required?
# TODO: consider version_aliases: list[str] = [] # remaining tags

# Get links to other resources
url: HttpUrl | None = Field(..., description="Link to get this resource")
url: HttpUrl = Field(
..., description="Link to get this resource"
) # TODO: should be nullable
model_config = ConfigDict(
extra="ignore",
json_schema_extra={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ async def update_project_metadata(
@_exception_mapper({status.HTTP_404_NOT_FOUND: PricingUnitNotFoundError})
async def get_project_node_pricing_unit(
self, *, project_id: UUID, node_id: UUID
) -> PricingUnitGet | None:
) -> PricingUnitGet:
response = await self.client.get(
f"/projects/{project_id}/nodes/{node_id}/pricing-unit",
cookies=self.session_cookies,
Expand Down Expand Up @@ -559,7 +559,7 @@ async def get_wallet(self, *, wallet_id: int) -> WalletGetWithAvailableCredits:
return data

@_exception_mapper(_WALLET_STATUS_MAP)
async def get_project_wallet(self, *, project_id: ProjectID) -> WalletGet | None:
async def get_project_wallet(self, *, project_id: ProjectID) -> WalletGet:
response = await self.client.get(
f"/projects/{project_id}/wallet",
cookies=self.session_cookies,
Expand Down

0 comments on commit 11cb8aa

Please sign in to comment.