From dfa70a141a5c3a6d42578e62e5905d807bb35713 Mon Sep 17 00:00:00 2001 From: Yashar Robert Date: Sat, 30 Mar 2024 17:33:48 +0100 Subject: [PATCH] Allow read-only mode --- dcatd.yml | 1 + src/datacatalog/application.py | 3 ++- src/datacatalog/plugins/postgres/__init__.py | 2 +- src/datacatalog/plugins/postgres/config_schema.yml | 5 +++++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/dcatd.yml b/dcatd.yml index 2d335be..8dd3e45 100644 --- a/dcatd.yml +++ b/dcatd.yml @@ -59,6 +59,7 @@ storage_postgres: pass: ${DB_PASS} port: ${DB_PORT} user: ${DB_USER} + mode: ${DB_MODE:-READWRITE} storage_swift: user: ${SWIFT_USER:-catalogus} diff --git a/src/datacatalog/application.py b/src/datacatalog/application.py index 6b7a9a8..5ebf655 100644 --- a/src/datacatalog/application.py +++ b/src/datacatalog/application.py @@ -173,7 +173,8 @@ async def _on_startup(app): if r.exception is not None: raise r.exception await startup_actions.run_startup_actions(app) - await NotificationHandler(app).setup_notification_handling() + if app.config['storage_postgres'].get("mode", '') != "READONLY": + await NotificationHandler(app).setup_notification_handling() async def _on_cleanup(app): diff --git a/src/datacatalog/plugins/postgres/__init__.py b/src/datacatalog/plugins/postgres/__init__.py index f5ce590..e8759e0 100644 --- a/src/datacatalog/plugins/postgres/__init__.py +++ b/src/datacatalog/plugins/postgres/__init__.py @@ -144,7 +144,7 @@ async def initialize(app): raise else: break - while connect_attempt_tries_left >= 0: + while connect_attempt_tries_left >= 0 and dbconf.get('mode', 'READWRITE') != "READONLY": try: await app['pool'].execute(_Q_CREATE) await app['pool'].execute(_Q_CREATE_STARTUP_ACTIONS) diff --git a/src/datacatalog/plugins/postgres/config_schema.yml b/src/datacatalog/plugins/postgres/config_schema.yml index 72d82ab..fbfbf66 100644 --- a/src/datacatalog/plugins/postgres/config_schema.yml +++ b/src/datacatalog/plugins/postgres/config_schema.yml @@ -27,6 +27,11 @@ properties: type: integer max_inactive_connection_lifetime: type: number + mode: + type: string + enum: + - READONLY + - READWRITE required: - host - port