|
4 | 4 | from models_library.api_schemas_storage import FileLocation |
5 | 5 | from servicelib.aiohttp import status |
6 | 6 | from simcore_service_storage._meta import API_VTAG |
7 | | -from simcore_service_storage.models import StorageQueryParamsBase |
| 7 | +from simcore_service_storage.models import ( |
| 8 | + LocationPathParams, |
| 9 | + StorageQueryParamsBase, |
| 10 | + SyncMetadataQueryParams, |
| 11 | +) |
8 | 12 |
|
9 | 13 | router = APIRouter( |
10 | 14 | prefix=f"/{API_VTAG}", |
|
18 | 22 | ) |
19 | 23 | async def list_storage_locations( |
20 | 24 | _query: Annotated[StorageQueryParamsBase, Depends()], |
21 | | -): |
22 | | - ... |
23 | | - |
24 | | - |
25 | | -@routes.post( |
26 | | - f"/{API_VTAG}/locations/{{location_id}}:sync", name="synchronise_meta_data_table" |
27 | | -) |
28 | | -async def synchronise_meta_data_table(request: web.Request) -> web.Response: |
29 | | - query_params: SyncMetadataQueryParams = parse_request_query_parameters_as( |
30 | | - SyncMetadataQueryParams, request |
31 | | - ) |
32 | | - path_params = parse_request_path_parameters_as(LocationPathParams, request) |
33 | | - _logger.debug( |
34 | | - "received call to synchronise_meta_data_table with %s", |
35 | | - f"{path_params=}, {query_params=}", |
36 | | - ) |
37 | | - |
38 | | - dsm = cast( |
39 | | - SimcoreS3DataManager, |
40 | | - get_dsm_provider(request.app).get(SimcoreS3DataManager.get_location_id()), |
41 | | - ) |
42 | | - sync_results: list[StorageFileID] = [] |
43 | | - sync_coro = dsm.synchronise_meta_data_table(dry_run=query_params.dry_run) |
44 | | - |
45 | | - if query_params.fire_and_forget: |
46 | | - settings: Settings = request.app[APP_CONFIG_KEY] |
| 25 | +): ... |
47 | 26 |
|
48 | | - async def _go(): |
49 | | - timeout = settings.STORAGE_SYNC_METADATA_TIMEOUT |
50 | | - try: |
51 | | - result = await asyncio.wait_for(sync_coro, timeout=timeout) |
52 | | - _logger.info( |
53 | | - "Sync metadata table completed: %d entries removed", |
54 | | - len(result), |
55 | | - ) |
56 | | - except TimeoutError: |
57 | | - _logger.exception("Sync metadata table timed out (%s seconds)", timeout) |
58 | 27 |
|
59 | | - fire_and_forget_task( |
60 | | - _go(), |
61 | | - task_suffix_name="synchronise_meta_data_table", |
62 | | - fire_and_forget_tasks_collection=request.app[APP_FIRE_AND_FORGET_TASKS_KEY], |
63 | | - ) |
64 | | - else: |
65 | | - sync_results = await sync_coro |
| 28 | +@router.post("/locations/{location_id}:sync") |
| 29 | +async def synchronise_meta_data_table( |
| 30 | + _query: Annotated[SyncMetadataQueryParams, Depends()], |
| 31 | + _path: Annotated[LocationPathParams, Depends()], |
| 32 | +): |
| 33 | + ... |
66 | 34 |
|
67 | | - return web.json_response( |
68 | | - { |
69 | | - "error": None, |
70 | | - "data": { |
71 | | - "removed": sync_results, |
72 | | - "fire_and_forget": query_params.fire_and_forget, |
73 | | - "dry_run": query_params.dry_run, |
74 | | - }, |
75 | | - }, |
76 | | - dumps=json_dumps, |
77 | | - ) |
| 35 | + # return web.json_response( |
| 36 | + # { |
| 37 | + # "error": None, |
| 38 | + # "data": { |
| 39 | + # "removed": sync_results, |
| 40 | + # "fire_and_forget": query_params.fire_and_forget, |
| 41 | + # "dry_run": query_params.dry_run, |
| 42 | + # }, |
| 43 | + # }, |
| 44 | + # dumps=json_dumps, |
| 45 | + # ) |
0 commit comments