From fd41d2a6fa8d86824404c42546438b1e2aa4b495 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Sun, 1 May 2022 19:57:16 +0200 Subject: [PATCH] Launch database housekeeping tasks from runner --- bin/datastore.py | 16 ++++++++++++++++ bin/housekeep_database.py | 25 +++++++++++++++++++++++++ bin/runner.sh | 3 +++ 3 files changed, 44 insertions(+) create mode 100755 bin/housekeep_database.py diff --git a/bin/datastore.py b/bin/datastore.py index 151f06a..2ec5b3a 100644 --- a/bin/datastore.py +++ b/bin/datastore.py @@ -679,3 +679,19 @@ class Datastore: # We do not commit if we've been passed a cursor, instead # we assume that we are in the middle of a transaction + + def housekeep_event_log(self, cursor = None): + """ + Call housekeeping actions on the event log + """ + if cursor is None: + cur = self.conn.cursor() + else: + cur = cursor + + qry = "CALL augment_event_data();" + cur.execute(qry) + if cursor is None: + self.maybe_commit() + # We do not commit if we've been passed a cursor, instead + # we assume that we are in the middle of a transaction diff --git a/bin/housekeep_database.py b/bin/housekeep_database.py new file mode 100755 index 0000000..46f5af0 --- /dev/null +++ b/bin/housekeep_database.py @@ -0,0 +1,25 @@ +#!/usr/bin/python3 + +""" +Do housekeeping actions on the database. +""" + +import configuration +from datastore import Datastore + +if __name__ == '__main__': + + print("Reading configuration") + surveys = configuration.surveys() + + print("Connecting to database") + db = Datastore() + + print("Reading surveys") + for survey in surveys: + print(f'Survey: {survey["id"]} ({survey["schema"]})') + db.set_survey(survey["schema"]) + + db.housekeep_event_log() + + print("Done") diff --git a/bin/runner.sh b/bin/runner.sh index ed088b7..f214730 100755 --- a/bin/runner.sh +++ b/bin/runner.sh @@ -119,6 +119,9 @@ print_log "Process ASAQC queue" # export NODE_TLS_REJECT_UNAUTHORIZED=0 run $DOUGAL_ROOT/lib/www/server/queues/asaqc/index.js +print_log "Run database housekeeping actions" +run $BINDIR/housekeep_database.py + rm "$LOCKFILE" print_info "End run"