|
2 | 2 | from pathlib import Path |
3 | 3 | from typing import Annotated, Any |
4 | 4 |
|
| 5 | +from aiohttp import web |
5 | 6 | from models_library.api_schemas_storage.storage_schemas import ( |
6 | 7 | DEFAULT_NUMBER_OF_PATHS_PER_PAGE, |
7 | 8 | MAX_NUMBER_OF_PATHS_PER_PAGE, |
8 | 9 | ) |
9 | | -from pydantic import BaseModel, Field |
| 10 | +from pydantic import BaseModel, Field, HttpUrl |
10 | 11 |
|
11 | 12 | from ..api_schemas_rpc_async_jobs.async_jobs import ( |
12 | 13 | AsyncJobGet, |
@@ -50,12 +51,33 @@ def to_rpc_schema(self, location_id: LocationID) -> DataExportTaskStartInput: |
50 | 51 | ) |
51 | 52 |
|
52 | 53 |
|
| 54 | +class AsyncJobLinks(OutputSchema): |
| 55 | + status_href: HttpUrl |
| 56 | + abort_href: HttpUrl |
| 57 | + result_href: HttpUrl |
| 58 | + |
| 59 | + |
53 | 60 | class StorageAsyncJobGet(OutputSchema): |
54 | 61 | job_id: AsyncJobId |
| 62 | + links: AsyncJobLinks |
55 | 63 |
|
56 | 64 | @classmethod |
57 | | - def from_rpc_schema(cls, async_job_rpc_get: AsyncJobGet) -> "StorageAsyncJobGet": |
58 | | - return StorageAsyncJobGet(job_id=async_job_rpc_get.job_id) |
| 65 | + def from_rpc_schema( |
| 66 | + cls, app: web.Application, async_job_rpc_get: AsyncJobGet |
| 67 | + ) -> "StorageAsyncJobGet": |
| 68 | + 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 | + ), |
| 79 | + ) |
| 80 | + return StorageAsyncJobGet(job_id=async_job_rpc_get.job_id, links=links) |
59 | 81 |
|
60 | 82 |
|
61 | 83 | class StorageAsyncJobStatus(OutputSchema): |
|
0 commit comments