74 lines
2.5 KiB
Python
74 lines
2.5 KiB
Python
# db-manager - Builds and manages an OwlBoard database instance - To be run on a
|
|
# cron schedule
|
|
# Copyright (C) 2023 Frederick Boniface
|
|
|
|
# This program is free software: you can redistribute it and/or modify it under the
|
|
# terms of the GNU General Public License as published by the Free Software
|
|
# Foundation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
# You should have received a copy of the GNU General Public License along with this
|
|
# program. If not, see
|
|
# https://git.fjla.uk/OwlBoard/db-manager/src/branch/main/LICENSE
|
|
|
|
version = "2024.3.0"
|
|
print(f"main.py: Initialising db-manager v{version}")
|
|
|
|
#Third Party Imports
|
|
import os
|
|
import time
|
|
|
|
# Import logger
|
|
import logger as log
|
|
log.out(f"main.py: db-manager {version} Initialised on host {os.uname()[1]}", "INFO")
|
|
|
|
#Local Imports
|
|
import corpus, mongo, pis, mailer, timetable, reasonCodes
|
|
|
|
# Ensure count document exists in meta, wrap in while look to prevent crashing if the DB is not ready:
|
|
# Does this work when the DB is not initialised?
|
|
dbReady = False
|
|
while dbReady is False:
|
|
try:
|
|
mongo.metaCounters()
|
|
dbReady = True
|
|
except:
|
|
dbReady = False
|
|
|
|
## Run CORPUS Update
|
|
status = corpus.runUpdate()
|
|
|
|
## Run PIS Update
|
|
pis.runUpdate()
|
|
|
|
## Run reasonCodes update
|
|
reasonCodes.runUpdate()
|
|
|
|
## Run Timetable Update
|
|
timetable.runUpdate()
|
|
|
|
## Create general indexes
|
|
log.out('main.py: Requesting TTL Index Creation', "INFO")
|
|
mongo.createTtlIndex("users", "atime", 2629800)
|
|
|
|
registrations_ttl_seconds = 14405
|
|
try:
|
|
mongo.createTtlIndex("registrations", "time", registrations_ttl_seconds)
|
|
log.out(f"main.py: createTtlIndex on 'registrations' for {registrations_ttl_seconds} seconds was successful")
|
|
except Exception as e:
|
|
log.out("main.py: createTtlIndex creation error: ", e)
|
|
log.out("main.py: Attemt to drop collection and recreate, then create index")
|
|
mongo.dropCollection("registrations")
|
|
mongo.createTtlIndex("registrations", "time", registrations_ttl_seconds)
|
|
|
|
log.out(f"Indexes for 'registrations': {list(mongo.listIndexes('registrations'))}")
|
|
|
|
# Push version number to database for reporting
|
|
mongo.putVersion(version)
|
|
|
|
log.out(f"main.py: db-manager v{version} Complete", "INFO")
|
|
log.out(f"main.py: Mailing logs")
|
|
mailer.submitLogs() |