Merge branch 'dev' into staging

This commit is contained in:
florian 2024-05-28 22:51:11 +02:00
commit 6205f35415
No known key found for this signature in database
GPG key ID: 93EE47CC3D061500
4 changed files with 17 additions and 6 deletions

View file

@ -67,7 +67,7 @@ def backup_database(current_time: datetime, db: Database = None, backup_dir: Pat
db_user = db.database_uri.split("://")[1].split(":")[0]
db_password = db.database_uri.split("://")[1].split(":")[1].rsplit("@", 1)[0]
db_database_name = db.database_uri.split("/")[-1]
db_database_name = db.database_uri.split("/")[-1].split("?")[0]
if database in ("mariadb", "mysql"):
LOGGER.info("Creating a backup for the MariaDB/MySQL database ...")
@ -142,7 +142,7 @@ def restore_database(backup_file: Path, db: Database = None) -> Database:
db_user = db.database_uri.split("://")[1].split(":")[0]
db_password = db.database_uri.split("://")[1].split(":")[1].rsplit("@", 1)[0]
db_database_name = db.database_uri.split("/")[-1]
db_database_name = db.database_uri.split("/")[-1].split("?")[0]
if database in ("mariadb", "mysql"):
LOGGER.info("Restoring the MariaDB/MySQL database ...")

View file

@ -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 ...")
@ -489,7 +495,7 @@ class Database:
external_plugins_changed=metadata is not None and metadata.external_plugins_changed,
pro_plugins_changed=metadata is not None and metadata.pro_plugins_changed,
instances_changed=metadata is not None and metadata.instances_changed,
plugins_config_changed=self.check_plugin_changes(),
plugins_config_changed=[plugin.id for plugin in session.query(Plugins).with_entities(Plugins.id).filter_by(config_changed=True).all()],
)
except BaseException as e:
return str(e)

View file

@ -238,6 +238,7 @@ class JobScheduler(ApiCaller):
err = self.try_database_readonly()
if err:
self.__logger.error("Database is in read-only mode, pending jobs will not be executed")
return True
self.__job_success = True
@ -278,6 +279,7 @@ class JobScheduler(ApiCaller):
def run_once(self, plugins: Optional[List[str]] = None) -> bool:
err = self.try_database_readonly()
if err:
self.__logger.error("Database is in read-only mode, jobs will not be executed")
return True
threads = []
@ -310,6 +312,7 @@ class JobScheduler(ApiCaller):
def run_single(self, job_name: str) -> bool:
err = self.try_database_readonly()
if err:
self.__logger.error(f"Database is in read-only mode, single job {job_name} will not be executed")
return True
if self.__lock:
@ -384,7 +387,4 @@ class JobScheduler(ApiCaller):
self.db.retry_connection(fallback=True, log=False)
self.db.readonly = True
if self.db.readonly:
self.__logger.error("Database is in read-only mode, jobs will not be executed")
return self.db.readonly

View file

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