|
6 | 6 | from fastapi import APIRouter, Depends, Header, Query, Request, status |
7 | 7 | from fastapi.encoders import jsonable_encoder |
8 | 8 | from fastapi.responses import JSONResponse |
| 9 | +from fastapi_pagination.api import create_page |
9 | 10 | from models_library.api_schemas_webserver.projects import ProjectPatch |
10 | 11 | from models_library.api_schemas_webserver.projects_nodes import NodeOutputs |
11 | 12 | from models_library.clusters import ClusterID |
12 | 13 | from models_library.function_services_catalog.services import file_picker |
13 | 14 | from models_library.projects import ProjectID |
14 | 15 | from models_library.projects_nodes import InputID, InputTypes |
15 | 16 | from models_library.projects_nodes_io import NodeID |
16 | | -from pydantic import PositiveInt |
| 17 | +from pydantic import HttpUrl, PositiveInt |
17 | 18 | from pydantic.types import PositiveInt |
18 | 19 | from servicelib.logging_utils import log_context |
19 | 20 | from simcore_service_api_server._service_studies import StudiesService |
| 21 | +from simcore_service_api_server.models.api_resources import parse_resources_ids |
20 | 22 |
|
21 | 23 | from ...exceptions.backend_errors import ProjectAlreadyStartedError |
22 | 24 | from ...models.pagination import Page, PaginationParams |
@@ -97,10 +99,26 @@ async def list_study_jobs( |
97 | 99 | page_params: Annotated[PaginationParams, Depends()], |
98 | 100 | studies_service: Annotated[StudiesService, Depends(get_studies_service)], |
99 | 101 | url_for: Annotated[Callable, Depends(get_reverse_url_mapper)], |
100 | | - product_name: Annotated[str, Depends(get_product_name)], |
101 | 102 | ): |
102 | 103 | 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 | + ) |
104 | 122 |
|
105 | 123 |
|
106 | 124 | @router.post( |
@@ -434,3 +452,30 @@ async def replace_study_job_custom_metadata( |
434 | 452 | job_id=job_id, |
435 | 453 | ), |
436 | 454 | ) |
| 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