Skip to content

Commit e133506

Browse files
committed
add method for getting full solver release history
1 parent 574b885 commit e133506

File tree

3 files changed

+60
-19
lines changed

3 files changed

+60
-19
lines changed

services/api-server/src/simcore_service_api_server/_service_solvers.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,41 @@ async def get_latest_release(
7070
)
7171

7272
return Solver.create_from_service(service)
73+
74+
async def solver_release_history(
75+
self,
76+
*,
77+
user_id: int,
78+
solver_key: SolverKeyId,
79+
product_name: str,
80+
) -> list[Solver]:
81+
82+
service_releases: list[ServiceRelease] = []
83+
for page_params in iter_pagination_params(limit=DEFAULT_PAGINATION_LIMIT):
84+
releases, page_meta = await self._catalog_service.list_release_history(
85+
user_id=user_id,
86+
service_key=solver_key,
87+
product_name=product_name,
88+
offset=page_params.offset,
89+
limit=page_params.limit,
90+
)
91+
page_params.total_number_of_items = page_meta.total
92+
service_releases.extend(releases)
93+
94+
service_instance = await self._catalog_service.get(
95+
user_id=user_id,
96+
name=solver_key,
97+
version=service_releases[-1].version,
98+
product_name=product_name,
99+
)
100+
101+
return [
102+
Solver.create_from_service_release(
103+
service_key=service_instance.key,
104+
description=service_instance.description,
105+
contact=service_instance.contact,
106+
name=service_instance.name,
107+
service=service,
108+
)
109+
for service in service_releases
110+
]

services/api-server/src/simcore_service_api_server/models/schemas/solvers.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
from models_library.api_schemas_catalog.services import LatestServiceGet, ServiceGetV2
44
from models_library.basic_regex import PUBLIC_VARIABLE_NAME_RE
5+
from models_library.emails import LowerCaseEmailStr
56
from models_library.services import ServiceMetaDataPublished
7+
from models_library.services_history import ServiceRelease
68
from models_library.services_regex import COMPUTATIONAL_SERVICE_KEY_RE
9+
from models_library.services_types import ServiceKey
710
from pydantic import BaseModel, ConfigDict, Field, StringConstraints
811

912
from ...models.schemas._base import BaseService
@@ -80,6 +83,25 @@ def create_from_service(cls, service: ServiceGetV2 | LatestServiceGet) -> "Solve
8083
**data,
8184
)
8285

86+
@classmethod
87+
def create_from_service_release(
88+
cls,
89+
*,
90+
service_key: ServiceKey,
91+
description: str,
92+
contact: LowerCaseEmailStr | None,
93+
name: str,
94+
service: ServiceRelease
95+
) -> "Solver":
96+
return cls(
97+
id=service_key,
98+
version=service.version,
99+
title=name,
100+
url=None,
101+
description=description,
102+
maintainer=contact or "",
103+
)
104+
83105
@classmethod
84106
def compose_resource_name(cls, key: str, version: str) -> str:
85107
return compose_resource_name("solvers", key, "releases", version)

services/api-server/src/simcore_service_api_server/services_http/catalog.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -171,25 +171,6 @@ async def get_service_ports(
171171

172172
return TypeAdapter(list[SolverPort]).validate_python(response.json())
173173

174-
async def list_latest_releases(
175-
self, *, user_id: UserID, product_name: ProductName
176-
) -> list[Solver]:
177-
services = await self.list_services(
178-
user_id=user_id,
179-
product_name=product_name,
180-
predicate=None,
181-
type_filter="COMPUTATIONAL",
182-
)
183-
solvers = [service.to_solver() for service in services]
184-
185-
latest_releases: dict[SolverKeyId, Solver] = {}
186-
for solver in solvers:
187-
latest = latest_releases.setdefault(solver.id, solver)
188-
if latest.pep404_version < solver.pep404_version:
189-
latest_releases[solver.id] = solver
190-
191-
return list(latest_releases.values())
192-
193174
async def list_service_releases(
194175
self,
195176
*,

0 commit comments

Comments
 (0)