From 228992bf152478a3980389a11e75258dd72b7547 Mon Sep 17 00:00:00 2001 From: Joonatan Makinen Date: Mon, 21 Dec 2020 08:46:45 +0200 Subject: [PATCH] add aiojobs setup and add pre-query condition --- docker-compose.yml | 4 ++-- metadata_backend/api/handlers.py | 4 ++++ metadata_backend/server.py | 10 ++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 20992a5f6..3edaba9a5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,7 +21,7 @@ services: - "OIDC_URL=http://mockauth:8000" # Enable this we working with front-end on localhost # or change to http://frontend:3000 if started using docker-compose - # - "REDIRECT_URL=http://localhost:3000" + - "REDIRECT_URL=http://localhost:3000" - "JWK_URL=http://mockauth:8000/keyset" - "AUTH_REFERER=http://mockauth:8000/" - "LOG_LEVEL=DEBUG" @@ -52,4 +52,4 @@ services: - ./tests/integration/mock_auth.py:/mock_auth.py entrypoint: ["python", "/mock_auth.py", "0.0.0.0", "8000"] volumes: - data: + data: diff --git a/metadata_backend/api/handlers.py b/metadata_backend/api/handlers.py index fb9547fc5..e91c20b3d 100644 --- a/metadata_backend/api/handlers.py +++ b/metadata_backend/api/handlers.py @@ -888,6 +888,10 @@ async def data_mirroring(self, dataset_id: str, db_client: AsyncIOMotorClient) - query = MultiDictProxy(MultiDict([("egaStableId", dataset_id)])) _, _, _, total_objects = await Operator(db_client).query_metadata_database("dataset", query, 1, 1, []) if total_objects > 0: + LOG.info(f"Dataset {dataset_id} has already been mirrored into the database.") + # Idea with this is to query for a dataset with the exactly same egaStableId value + # and if none is found, then it is mirrored from EGA. As of now, this query doesn't work properly + else: ega_data = MetadataMirror().mirror_dataset(dataset_id) operator = Operator(db_client) for schema_type in ega_data: diff --git a/metadata_backend/server.py b/metadata_backend/server.py index 2bd8053c7..4db9feb01 100644 --- a/metadata_backend/server.py +++ b/metadata_backend/server.py @@ -4,6 +4,7 @@ import uvloop from aiohttp import web +from aiojobs.aiohttp import setup from cryptography.fernet import Fernet import secrets import time @@ -55,7 +56,6 @@ async def init() -> web.Application: server.middlewares.append(check_login) rest_handler = RESTApiHandler() submission_handler = SubmissionAPIHandler() - mirror_handler = DataMirrorHandler() api_routes = [ web.get("/schemas", rest_handler.get_schema_types), web.get("/schemas/{schema}", rest_handler.get_json_schema), @@ -79,7 +79,6 @@ async def init() -> web.Application: web.delete("/users/{userId}", rest_handler.delete_user), web.post("/submit", submission_handler.submit), web.post("/validate", submission_handler.validate), - web.get("/mirror/{datasetId}", mirror_handler.mirror_dataset), ] server.router.add_routes(api_routes) LOG.info("Server configurations and routes loaded") @@ -91,6 +90,13 @@ async def init() -> web.Application: ] server.router.add_routes(aai_routes) LOG.info("AAI routes loaded") + mirror_handler = DataMirrorHandler() + mirror_routes = [ + web.get("/mirror/{datasetId}", mirror_handler.mirror_dataset), + ] + server.router.add_routes(mirror_routes) + setup(server) + LOG.info("Mirroring routes loaded") if frontend_static_files.exists(): static_handler = StaticHandler(frontend_static_files) frontend_routes = [