Skip to content

Commit 87211f2

Browse files
committed
add links also to status response
1 parent 881646a commit 87211f2

File tree

2 files changed

+36
-23
lines changed
  • packages/models-library/src/models_library/api_schemas_webserver
  • services/web/server/src/simcore_service_webserver/storage

2 files changed

+36
-23
lines changed

packages/models-library/src/models_library/api_schemas_webserver/storage.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
DEFAULT_NUMBER_OF_PATHS_PER_PAGE,
88
MAX_NUMBER_OF_PATHS_PER_PAGE,
99
)
10-
from pydantic import BaseModel, Field, HttpUrl
10+
from pydantic import BaseModel, Field
1111

1212
from ..api_schemas_rpc_async_jobs.async_jobs import (
1313
AsyncJobGet,
@@ -52,9 +52,17 @@ def to_rpc_schema(self, location_id: LocationID) -> DataExportTaskStartInput:
5252

5353

5454
class AsyncJobLinks(OutputSchema):
55-
status_href: HttpUrl
56-
abort_href: HttpUrl
57-
result_href: HttpUrl
55+
status_href: str
56+
abort_href: str
57+
result_href: str
58+
59+
@classmethod
60+
def from_job_id(cls, app: web.Application, job_id: str) -> "AsyncJobLinks":
61+
return AsyncJobLinks(
62+
status_href=f"{app.router['get_async_job_status'].url_for(job_id=job_id)}",
63+
abort_href=f"{app.router['abort_async_job'].url_for(job_id=job_id)}",
64+
result_href=f"{app.router['get_async_job_result'].url_for(job_id=job_id)}",
65+
)
5866

5967

6068
class StorageAsyncJobGet(OutputSchema):
@@ -63,21 +71,13 @@ class StorageAsyncJobGet(OutputSchema):
6371

6472
@classmethod
6573
def from_rpc_schema(
66-
cls, app: web.Application, async_job_rpc_get: AsyncJobGet
74+
cls, *, app: web.Application, async_job_rpc_get: AsyncJobGet
6775
) -> "StorageAsyncJobGet":
6876
job_id = f"{async_job_rpc_get.job_id}"
69-
links = AsyncJobLinks(
70-
status_href=HttpUrl(
71-
f"{app.router['get_async_job_status'].url_for(job_id=job_id)}"
72-
),
73-
abort_href=HttpUrl(
74-
f"{app.router['abort_async_job'].url_for(job_id=job_id)}"
75-
),
76-
result_href=HttpUrl(
77-
f"{app.router['get_async_job_result'].url_for(job_id=job_id)}"
78-
),
77+
return StorageAsyncJobGet(
78+
job_id=async_job_rpc_get.job_id,
79+
links=AsyncJobLinks.from_job_id(app=app, job_id=job_id),
7980
)
80-
return StorageAsyncJobGet(job_id=async_job_rpc_get.job_id, links=links)
8181

8282

8383
class StorageAsyncJobStatus(OutputSchema):
@@ -86,17 +86,21 @@ class StorageAsyncJobStatus(OutputSchema):
8686
done: bool
8787
started: datetime
8888
stopped: datetime | None
89+
links: AsyncJobLinks
8990

9091
@classmethod
9192
def from_rpc_schema(
92-
cls, async_job_rpc_status: AsyncJobStatus
93+
cls, *, app: web.Application, async_job_rpc_status: AsyncJobStatus
9394
) -> "StorageAsyncJobStatus":
9495
return StorageAsyncJobStatus(
9596
job_id=async_job_rpc_status.job_id,
9697
progress=async_job_rpc_status.progress,
9798
done=async_job_rpc_status.done,
9899
started=async_job_rpc_status.started,
99100
stopped=async_job_rpc_status.stopped,
101+
links=AsyncJobLinks.from_job_id(
102+
app=app, job_id=f"{async_job_rpc_status.job_id}"
103+
),
100104
)
101105

102106

services/web/server/src/simcore_service_webserver/storage/_rest.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,9 @@ class _PathParams(BaseModel):
432432
),
433433
)
434434
return create_data_response(
435-
StorageAsyncJobGet.from_rpc_schema(async_job_rpc_get),
435+
StorageAsyncJobGet.from_rpc_schema(
436+
app=request.app, async_job_rpc_get=async_job_rpc_get
437+
),
436438
status=status.HTTP_202_ACCEPTED,
437439
)
438440

@@ -458,7 +460,10 @@ async def get_async_jobs(request: web.Request) -> web.Response:
458460
filter_="",
459461
)
460462
return create_data_response(
461-
[StorageAsyncJobGet.from_rpc_schema(job) for job in user_async_jobs],
463+
[
464+
StorageAsyncJobGet.from_rpc_schema(app=request.app, async_job_rpc_get=job)
465+
for job in user_async_jobs
466+
],
462467
status=status.HTTP_200_OK,
463468
)
464469

@@ -484,7 +489,9 @@ async def get_async_job_status(request: web.Request) -> web.Response:
484489
),
485490
)
486491
return create_data_response(
487-
StorageAsyncJobStatus.from_rpc_schema(async_job_rpc_status),
492+
StorageAsyncJobStatus.from_rpc_schema(
493+
app=request.app, async_job_rpc_status=async_job_rpc_status
494+
),
488495
status=status.HTTP_200_OK,
489496
)
490497

@@ -510,9 +517,11 @@ async def abort_async_job(request: web.Request) -> web.Response:
510517
),
511518
)
512519
return web.Response(
513-
status=status.HTTP_200_OK
514-
if async_job_rpc_abort.result
515-
else status.HTTP_500_INTERNAL_SERVER_ERROR
520+
status=(
521+
status.HTTP_200_OK
522+
if async_job_rpc_abort.result
523+
else status.HTTP_500_INTERNAL_SERVER_ERROR
524+
)
516525
)
517526

518527

0 commit comments

Comments
 (0)