|
13 | 13 | from models_library.users import UserID |
14 | 14 | from servicelib.rabbitmq import RPCRouter |
15 | 15 | from servicelib.utils import limited_gather |
16 | | -from simcore_service_director_v2.models.comp_tasks import ComputationTaskForRpcDBGet |
17 | 16 |
|
| 17 | +from ...core.errors import ComputationalRunNotFoundError |
| 18 | +from ...models.comp_runs import CompRunsAtDB |
| 19 | +from ...models.comp_tasks import ComputationTaskForRpcDBGet |
18 | 20 | from ...modules.db.repositories.comp_runs import CompRunsRepository |
19 | 21 | from ...modules.db.repositories.comp_tasks import CompTasksRepository |
20 | 22 | from ...utils import dask as dask_utils |
@@ -95,6 +97,19 @@ async def _fetch_task_log( |
95 | 97 | return None |
96 | 98 |
|
97 | 99 |
|
| 100 | +async def _get_latest_run_or_none( |
| 101 | + comp_runs_repo: CompRunsRepository, |
| 102 | + user_id: UserID, |
| 103 | + project_uuid: ProjectID, |
| 104 | +) -> CompRunsAtDB | None: |
| 105 | + try: |
| 106 | + return await comp_runs_repo.get( |
| 107 | + user_id=user_id, project_id=project_uuid, iteration=None |
| 108 | + ) |
| 109 | + except ComputationalRunNotFoundError: |
| 110 | + return None |
| 111 | + |
| 112 | + |
98 | 113 | @router.expose(reraise_if_error_type=()) |
99 | 114 | async def list_computations_latest_iteration_tasks_page( |
100 | 115 | app: FastAPI, |
@@ -127,13 +142,15 @@ async def list_computations_latest_iteration_tasks_page( |
127 | 142 | # Fetch latest run for each project concurrently |
128 | 143 | latest_runs = await limited_gather( |
129 | 144 | *[ |
130 | | - comp_runs_repo.get(user_id=user_id, project_id=project_uuid, iteration=None) |
| 145 | + _get_latest_run_or_none(comp_runs_repo, user_id, project_uuid) |
131 | 146 | for project_uuid in unique_project_uuids |
132 | 147 | ], |
133 | 148 | limit=20, |
134 | 149 | ) |
135 | 150 | # Build a dict: project_uuid -> iteration |
136 | | - project_uuid_to_iteration = {run.project_uuid: run.iteration for run in latest_runs} |
| 151 | + project_uuid_to_iteration = { |
| 152 | + run.project_uuid: run.iteration for run in latest_runs if run is not None |
| 153 | + } |
137 | 154 |
|
138 | 155 | # Run all log fetches concurrently |
139 | 156 | log_files = await limited_gather( |
|
0 commit comments