2023-02-11 12:03:39 +00:00
|
|
|
# db-manager - Builds and manages an OwlBoard database instance - To be run on a
|
|
|
|
# cron schedule
|
2023-02-09 20:58:48 +00:00
|
|
|
# Copyright (C) 2023 Frederick Boniface
|
|
|
|
|
2023-02-11 12:03:39 +00:00
|
|
|
# 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.
|
2023-02-09 20:58:48 +00:00
|
|
|
|
2023-02-11 12:03:39 +00:00
|
|
|
# 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.
|
2023-02-09 20:58:48 +00:00
|
|
|
|
2023-02-11 12:03:39 +00:00
|
|
|
# You should have received a copy of the GNU General Public License along with this
|
|
|
|
# program. If not, see
|
2023-02-09 21:47:59 +00:00
|
|
|
# https://git.fjla.uk/OwlBoard/db-manager/src/branch/main/LICENSE
|
|
|
|
|
2024-03-01 20:39:13 +00:00
|
|
|
version = "2024.3.0"
|
2023-02-11 22:05:30 +00:00
|
|
|
print(f"main.py: Initialising db-manager v{version}")
|
2023-02-11 12:03:39 +00:00
|
|
|
|
2023-02-11 15:16:25 +00:00
|
|
|
#Third Party Imports
|
2023-02-09 21:47:59 +00:00
|
|
|
import os
|
|
|
|
import time
|
|
|
|
|
2023-05-31 22:09:09 +01:00
|
|
|
# Import logger
|
2023-02-11 15:16:25 +00:00
|
|
|
import logger as log
|
2023-06-06 12:59:44 +01:00
|
|
|
log.out(f"main.py: db-manager {version} Initialised on host {os.uname()[1]}", "INFO")
|
2023-02-09 21:47:59 +00:00
|
|
|
|
2023-05-31 22:09:09 +01:00
|
|
|
#Local Imports
|
2023-06-11 22:14:03 +01:00
|
|
|
import corpus, mongo, pis, mailer, timetable, reasonCodes
|
2023-05-08 19:55:09 +01:00
|
|
|
|
2023-05-31 22:09:09 +01:00
|
|
|
# Ensure count document exists in meta, wrap in while look to prevent crashing if the DB is not ready:
|
2023-06-01 16:49:47 +01:00
|
|
|
# Does this work when the DB is not initialised?
|
2023-05-08 19:55:09 +01:00
|
|
|
dbReady = False
|
|
|
|
while dbReady is False:
|
|
|
|
try:
|
|
|
|
mongo.metaCounters()
|
|
|
|
dbReady = True
|
|
|
|
except:
|
|
|
|
dbReady = False
|
2023-02-16 22:23:54 +00:00
|
|
|
|
2023-06-06 12:59:44 +01:00
|
|
|
## Run CORPUS Update
|
|
|
|
status = corpus.runUpdate()
|
2023-05-08 19:55:09 +01:00
|
|
|
|
2023-05-31 22:09:09 +01:00
|
|
|
## Run PIS Update
|
|
|
|
pis.runUpdate()
|
2023-05-08 19:55:09 +01:00
|
|
|
|
2023-06-11 22:14:03 +01:00
|
|
|
## Run reasonCodes update
|
|
|
|
reasonCodes.runUpdate()
|
|
|
|
|
2023-05-31 19:04:33 +01:00
|
|
|
## Run Timetable Update
|
|
|
|
timetable.runUpdate()
|
|
|
|
|
2023-06-06 12:59:44 +01:00
|
|
|
## Create general indexes
|
2023-05-08 19:55:09 +01:00
|
|
|
log.out('main.py: Requesting TTL Index Creation', "INFO")
|
|
|
|
mongo.createTtlIndex("users", "atime", 2629800)
|
2024-02-19 11:57:31 +00:00
|
|
|
|
2024-03-01 22:14:06 +00:00
|
|
|
registrations_ttl_seconds = 14405
|
2024-02-19 11:57:31 +00:00
|
|
|
try:
|
2024-03-01 22:14:06 +00:00
|
|
|
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")
|
2024-02-19 11:57:31 +00:00
|
|
|
mongo.dropCollection("registrations")
|
2024-03-01 22:14:06 +00:00
|
|
|
mongo.createTtlIndex("registrations", "time", registrations_ttl_seconds)
|
2023-02-11 22:05:30 +00:00
|
|
|
|
2024-03-01 20:39:13 +00:00
|
|
|
log.out(f"Indexes for 'registrations': {list(mongo.listIndexes('registrations'))}")
|
|
|
|
|
2023-03-13 19:46:03 +00:00
|
|
|
# Push version number to database for reporting
|
|
|
|
mongo.putVersion(version)
|
|
|
|
|
2023-05-31 19:04:33 +01:00
|
|
|
log.out(f"main.py: db-manager v{version} Complete", "INFO")
|
|
|
|
log.out(f"main.py: Mailing logs")
|
|
|
|
mailer.submitLogs()
|