From af99f901b91e308a263972cc0ebb22adf4bef742 Mon Sep 17 00:00:00 2001 From: Cheng-Kai Wang Date: Thu, 28 Aug 2025 16:25:32 +0200 Subject: [PATCH 1/3] Update docker-compose files to expose rest_postgres_db port --- docker-compose.override.dev.yml | 4 ---- docker-compose.yml | 8 +++++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/docker-compose.override.dev.yml b/docker-compose.override.dev.yml index 9487306..ac10362 100644 --- a/docker-compose.override.dev.yml +++ b/docker-compose.override.dev.yml @@ -4,7 +4,3 @@ services: build: context: .. dockerfile: omotes-rest/dev.Dockerfile - - rest_postgres_db: - ports: - - "${POSTGRES_PORT}:5432" diff --git a/docker-compose.yml b/docker-compose.yml index 457f5d1..c0ae15b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,8 @@ networks: omotes: external: true -# mapeditor-net: -# external: true + mapeditor-net: + external: true volumes: db-data: @@ -12,7 +12,7 @@ services: image: ghcr.io/project-omotes/omotes_rest:1.2.0 networks: - omotes -# - mapeditor-net + - mapeditor-net ports: - "9200:9200" environment: @@ -46,6 +46,8 @@ services: - "./src/postgres-init.sql:/setup/init.sql" networks: - omotes + ports: + - "${POSTGRES_PORT}:5432" environment: PGDATA: /var/lib/POSTGRES/data POSTGRES_DB: ${POSTGRES_DATABASE} From d0e3d1c0a15747e331fa358e73ff1f8e8207ed92 Mon Sep 17 00:00:00 2001 From: Cheng-Kai Wang Date: Thu, 28 Aug 2025 16:36:04 +0200 Subject: [PATCH 2/3] Add documentation regarding monitoring job runs script --- README.md | 4 ++++ doc/Monitoring_job_runs.md | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 doc/Monitoring_job_runs.md diff --git a/README.md b/README.md index 827696a..6b44973 100644 --- a/README.md +++ b/README.md @@ -105,3 +105,7 @@ First, change directory: `cd src/` - Perform all revisions: `alembic upgrade head` - Downgrade to a revision: `alembic downgrade ` (revision 'base' to undo everything.) + +## Monitoring job runs + +A SQL script can be applied optionally to monitor omotes job runs. More details see [Monitoring_job_runs](/doc/Monitoring_job_runs.md) diff --git a/doc/Monitoring_job_runs.md b/doc/Monitoring_job_runs.md new file mode 100644 index 0000000..3159deb --- /dev/null +++ b/doc/Monitoring_job_runs.md @@ -0,0 +1,39 @@ +## Introduction + +To monitor OMOTES job runs in a single table. The script below can be applied manually in OMOTES REST PostgreSQL database. + +```sql +CREATE TABLE job_logs ( + LIKE job_rest INCLUDING DEFAULTS, + deleted_at TIMESTAMP DEFAULT NULL +); + +CREATE OR REPLACE FUNCTION backup_job_to_logs() +RETURNS TRIGGER AS $$ +BEGIN + IF TG_OP = 'DELETE' THEN + -- On DELETE: remove existing log row (if any), then insert with deleted_at + DELETE FROM job_logs WHERE job_id = OLD.job_id; + + INSERT INTO job_logs + SELECT OLD.*, now(); + + RETURN OLD; + + ELSE + -- On INSERT or UPDATE: remove existing log row (if any), then insert new + DELETE FROM job_logs WHERE job_id = NEW.job_id; + + INSERT INTO job_logs + SELECT NEW.*, NULL; + + RETURN NEW; + END IF; +END; +$$ LANGUAGE plpgsql; + +CREATE OR REPLACE TRIGGER trigger_backup_all +AFTER INSERT OR UPDATE OR DELETE ON job_rest +FOR EACH ROW +EXECUTE FUNCTION backup_job_to_logs(); +``` \ No newline at end of file From 3645543fd95a0ad421a2c8a222458b19c6c849cf Mon Sep 17 00:00:00 2001 From: Cheng-Kai Wang Date: Thu, 28 Aug 2025 16:44:19 +0200 Subject: [PATCH 3/3] Fix review comment --- .env.template | 1 - 1 file changed, 1 deletion(-) diff --git a/.env.template b/.env.template index 3533663..2593396 100644 --- a/.env.template +++ b/.env.template @@ -8,7 +8,6 @@ RABBITMQ_VIRTUALHOST=omotes POSTGRES_ROOT_USER=root POSTGRES_ROOT_PASSWORD=1234 -POSTGRES_DEV_PORT=7432 POSTGRES_DATABASE=omotes_rest POSTGRES_HOST=localhost POSTGRES_PORT=7432