Skip to content

Commit dc4ebe8

Browse files
committed
drafts list_study_jobs
1 parent 5d74010 commit dc4ebe8

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

services/api-server/src/simcore_service_api_server/api/routes/solvers_jobs_getters.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,12 @@ def _update_job_urls(
163163
include_in_schema=False, # TO BE RELEASED in 0.8
164164
)
165165
async def list_all_solvers_jobs(
166-
user_id: Annotated[PositiveInt, Depends(get_current_user_id)],
167166
page_params: Annotated[PaginationParams, Depends()],
168167
solver_service: Annotated[SolverService, Depends(get_solver_service)],
169168
url_for: Annotated[Callable, Depends(get_reverse_url_mapper)],
170-
product_name: Annotated[str, Depends(get_product_name)],
171169
):
172170

173171
jobs, meta = await solver_service.list_jobs(
174-
product_name=product_name,
175-
user_id=user_id,
176172
offset=page_params.offset,
177173
limit=page_params.limit,
178174
)
@@ -193,7 +189,7 @@ async def list_all_solvers_jobs(
193189
response_model=list[Job],
194190
responses=JOBS_STATUS_CODES,
195191
description=create_route_description(
196-
base="List of jobs in a specific released solver",
192+
base="List of jobs in a specific released solver (limited to 20 jobs)",
197193
deprecated=True,
198194
alternative="GET /{solver_key}/releases/{version}/jobs/page",
199195
changelog=[
@@ -214,8 +210,6 @@ async def list_jobs(
214210
url_for: Annotated[Callable, Depends(get_reverse_url_mapper)],
215211
product_name: Annotated[str, Depends(get_product_name)],
216212
):
217-
"""List of jobs in a specific released solver (limited to 20 jobs)"""
218-
219213
solver = await solver_service.get_solver(
220214
user_id=user_id,
221215
solver_key=solver_key,

services/api-server/src/simcore_service_api_server/api/routes/studies_jobs.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@
66
from fastapi import APIRouter, Depends, Header, Query, Request, status
77
from fastapi.encoders import jsonable_encoder
88
from fastapi.responses import JSONResponse
9+
from fastapi_pagination.api import create_page
910
from models_library.api_schemas_webserver.projects import ProjectPatch
1011
from models_library.api_schemas_webserver.projects_nodes import NodeOutputs
1112
from models_library.clusters import ClusterID
1213
from models_library.function_services_catalog.services import file_picker
1314
from models_library.projects import ProjectID
1415
from models_library.projects_nodes import InputID, InputTypes
1516
from models_library.projects_nodes_io import NodeID
16-
from pydantic import PositiveInt
17+
from pydantic import HttpUrl, PositiveInt
1718
from pydantic.types import PositiveInt
1819
from servicelib.logging_utils import log_context
1920
from simcore_service_api_server._service_studies import StudiesService
21+
from simcore_service_api_server.models.api_resources import parse_resources_ids
2022

2123
from ...exceptions.backend_errors import ProjectAlreadyStartedError
2224
from ...models.pagination import Page, PaginationParams
@@ -97,10 +99,26 @@ async def list_study_jobs(
9799
page_params: Annotated[PaginationParams, Depends()],
98100
studies_service: Annotated[StudiesService, Depends(get_studies_service)],
99101
url_for: Annotated[Callable, Depends(get_reverse_url_mapper)],
100-
product_name: Annotated[str, Depends(get_product_name)],
101102
):
102103
msg = f"list study jobs study_id={study_id!r} with pagination={page_params!r}. SEE https://github.com/ITISFoundation/osparc-simcore/issues/4177"
103-
raise NotImplementedError(msg)
104+
_logger.debug(msg)
105+
106+
jobs, meta = await studies_service.list_jobs(
107+
study_id=study_id,
108+
offset=page_params.offset,
109+
limit=page_params.limit,
110+
)
111+
112+
for job in jobs:
113+
study_id_str, job_id = parse_resources_ids(job.resource_name)
114+
assert study_id_str == f"{study_id}"
115+
_update_job_urls(job=job, study_id=study_id, job_id=job_id, url_for=url_for)
116+
117+
return create_page(
118+
jobs,
119+
total=meta.total,
120+
params=page_params,
121+
)
104122

105123

106124
@router.post(
@@ -434,3 +452,30 @@ async def replace_study_job_custom_metadata(
434452
job_id=job_id,
435453
),
436454
)
455+
456+
457+
def _update_job_urls(
458+
*,
459+
job: Job,
460+
study_id: StudyID,
461+
job_id: JobID | str,
462+
url_for: Callable[..., HttpUrl],
463+
) -> Job:
464+
job.url = url_for(
465+
get_study_job.__name__,
466+
study_id=study_id,
467+
job_id=job_id,
468+
)
469+
470+
job.runner_url = url_for(
471+
"get_study",
472+
study_id=study_id,
473+
)
474+
475+
job.outputs_url = url_for(
476+
get_study_job_outputs.__name__,
477+
study_id=study_id,
478+
job_id=job_id,
479+
)
480+
481+
return job

0 commit comments

Comments
 (0)