mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
chore: Add test_read method to Database class for testing read access to the database and use it with the web UI
This commit is contained in:
parent
41e4834a06
commit
7f5d3cd937
2 changed files with 11 additions and 0 deletions
|
|
@ -215,6 +215,12 @@ class Database:
|
|||
if self.sql_engine:
|
||||
self.sql_engine.dispose()
|
||||
|
||||
def test_read(self):
|
||||
"""Test the read access to the database"""
|
||||
self.logger.debug("Testing read access to the database ...")
|
||||
with self.__db_session() as session:
|
||||
session.execute(text("SELECT 1"))
|
||||
|
||||
def test_write(self):
|
||||
"""Test the write access to the database"""
|
||||
self.logger.debug("Testing write access to the database ...")
|
||||
|
|
|
|||
|
|
@ -475,6 +475,11 @@ def before_request():
|
|||
except BaseException:
|
||||
ui_data["READONLY_MODE"] = True
|
||||
ui_data["LAST_DATABASE_RETRY"] = app.config["DB"].last_connection_retry.isoformat()
|
||||
else:
|
||||
try:
|
||||
app.config["DB"].test_read()
|
||||
except BaseException:
|
||||
ui_data["LAST_DATABASE_RETRY"] = app.config["DB"].last_connection_retry.isoformat()
|
||||
|
||||
app.config["DB"].readonly = ui_data.get("READONLY_MODE", False)
|
||||
with LOCK:
|
||||
|
|
|
|||
Loading…
Reference in a new issue