Launch database housekeeping tasks from runner

This commit is contained in:
D. Berge
2022-05-01 19:57:16 +02:00
parent 39690c991b
commit fd41d2a6fa
3 changed files with 44 additions and 0 deletions

View File

@@ -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

25
bin/housekeep_database.py Executable file
View File

@@ -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")

View File

@@ -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"