mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
Post soft merge fixes
This commit is contained in:
parent
cc0f189e7a
commit
e802d26bb1
4 changed files with 52 additions and 30 deletions
|
|
@ -61,28 +61,38 @@ class Config:
|
|||
return True
|
||||
return False
|
||||
|
||||
def wait_applying(self):
|
||||
def have_to_wait(self) -> bool:
|
||||
db_metadata = self._db.get_metadata()
|
||||
return (
|
||||
isinstance(db_metadata, str)
|
||||
or not db_metadata["is_initialized"]
|
||||
or any(
|
||||
v
|
||||
for k, v in db_metadata.items()
|
||||
if k in ("custom_configs_changed", "external_plugins_changed", "pro_plugins_changed", "plugins_config_changed", "instances_changed")
|
||||
)
|
||||
)
|
||||
|
||||
def wait_applying(self, startup: bool = False):
|
||||
current_time = datetime.now()
|
||||
ready = False
|
||||
while not ready and (datetime.now() - current_time).seconds < 240:
|
||||
db_metadata = self._db.get_metadata()
|
||||
if isinstance(db_metadata, str):
|
||||
self.__logger.error(f"An error occurred when checking for changes in the database : {db_metadata}")
|
||||
elif not any(
|
||||
if not startup:
|
||||
self.__logger.error(f"An error occurred when checking for changes in the database : {db_metadata}")
|
||||
elif db_metadata["is_initialized"] and not any(
|
||||
v
|
||||
for k, v in db_metadata.items()
|
||||
if k in ("custom_configs_changed", "external_plugins_changed", "pro_plugins_changed", "config_changed", "instances_changed")
|
||||
if k in ("custom_configs_changed", "external_plugins_changed", "pro_plugins_changed", "plugins_config_changed", "instances_changed")
|
||||
):
|
||||
ready = True
|
||||
continue
|
||||
self.__logger.warning("Scheduler is already applying a configuration, retrying in 5 seconds ...")
|
||||
sleep(5)
|
||||
|
||||
def have_to_wait(self) -> bool:
|
||||
db_metadata = self._db.get_metadata()
|
||||
return isinstance(db_metadata, str) or any(
|
||||
v
|
||||
for k, v in db_metadata.items()
|
||||
if k in ("custom_configs_changed", "external_plugins_changed", "pro_plugins_changed", "config_changed", "instances_changed")
|
||||
)
|
||||
if not ready:
|
||||
raise Exception("Too many retries while waiting for scheduler to apply configuration...")
|
||||
|
||||
def apply(
|
||||
self, instances: List[Dict[str, Any]], services: List[Dict[str, str]], configs: Optional[Dict[str, Dict[str, bytes]]] = None, first: bool = False
|
||||
|
|
@ -93,10 +103,6 @@ class Config:
|
|||
if err:
|
||||
return False
|
||||
|
||||
while not self._db.is_initialized():
|
||||
self.__logger.warning("Database is not initialized, retrying in 5 seconds ...")
|
||||
sleep(5)
|
||||
|
||||
self.wait_applying()
|
||||
|
||||
configs = configs or {}
|
||||
|
|
|
|||
|
|
@ -300,6 +300,16 @@ class Database:
|
|||
if session:
|
||||
session.remove()
|
||||
|
||||
def is_setting(self, setting: str, *, multisite: bool = False) -> bool:
|
||||
"""Check if the setting exists in the database and optionally if it's multisite"""
|
||||
with self.__db_session() as session:
|
||||
try:
|
||||
if multisite:
|
||||
return session.query(Settings).filter_by(id=setting, context="multisite").first() is not None
|
||||
return session.query(Settings).filter_by(id=setting).first() is not None
|
||||
except (ProgrammingError, OperationalError):
|
||||
return False
|
||||
|
||||
def initialize_db(self, version: str, integration: str = "Unknown") -> str:
|
||||
"""Initialize the database"""
|
||||
with self.__db_session() as session:
|
||||
|
|
@ -345,6 +355,7 @@ class Database:
|
|||
"external_plugins_changed": False,
|
||||
"pro_plugins_changed": False,
|
||||
"instances_changed": False,
|
||||
"plugins_config_changed": {},
|
||||
"last_custom_configs_change": None,
|
||||
"last_external_plugins_change": None,
|
||||
"last_pro_plugins_change": None,
|
||||
|
|
@ -366,6 +377,11 @@ class Database:
|
|||
if hasattr(metadata, key) and key not in ("database_version", "default"):
|
||||
data[key] = getattr(metadata, key)
|
||||
data["default"] = False
|
||||
|
||||
data["plugins_config_changed"] = {
|
||||
plugin.id: plugin.last_config_change
|
||||
for plugin in session.query(Plugins).with_entities(Plugins.id, Plugins.last_config_change).filter_by(config_changed=True).all()
|
||||
}
|
||||
except BaseException as e:
|
||||
if "doesn't exist" not in str(e):
|
||||
self.logger.debug(f"Can't get the metadata: {e}")
|
||||
|
|
|
|||
|
|
@ -835,14 +835,15 @@ if __name__ == "__main__":
|
|||
raise Exception(f"An error occurred when checking for changes in the database : {db_metadata}")
|
||||
|
||||
changes = {
|
||||
"custom_configs_changed": db_metadata["custom_configs_changed"],
|
||||
"instances_changed": db_metadata["instances_changed"],
|
||||
"external_plugins_changed": db_metadata["external_plugins_changed"],
|
||||
"pro_plugins_changed": db_metadata["pro_plugins_changed"],
|
||||
"last_custom_configs_change": db_metadata["last_custom_configs_change"],
|
||||
"last_instances_change": db_metadata["last_instances_change"],
|
||||
"last_external_plugins_change": db_metadata["last_external_plugins_change"],
|
||||
"last_pro_plugins_change": db_metadata["last_pro_plugins_change"],
|
||||
"external_plugins_changed": db_metadata["external_plugins_changed"],
|
||||
"last_external_plugins_change": db_metadata["last_external_plugins_change"],
|
||||
"custom_configs_changed": db_metadata["custom_configs_changed"],
|
||||
"last_custom_configs_change": db_metadata["last_custom_configs_change"],
|
||||
"plugins_config_changed": db_metadata["plugins_config_changed"],
|
||||
"instances_changed": db_metadata["instances_changed"],
|
||||
"last_instances_change": db_metadata["last_instances_change"],
|
||||
}
|
||||
|
||||
if SCHEDULER.db.readonly and changes == old_changes:
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ def wait_applying():
|
|||
elif not any(
|
||||
v
|
||||
for k, v in db_metadata.items()
|
||||
if k in ("custom_configs_changed", "external_plugins_changed", "pro_plugins_changed", "config_changed", "instances_changed")
|
||||
if k in ("custom_configs_changed", "external_plugins_changed", "pro_plugins_changed", "plugins_config_changed", "instances_changed")
|
||||
):
|
||||
ready = True
|
||||
continue
|
||||
|
|
@ -365,7 +365,7 @@ def inject_variables():
|
|||
if ui_data.get("PRO_LOADING") and not any(
|
||||
v
|
||||
for k, v in db_metadata.items()
|
||||
if k in ("custom_configs_changed", "external_plugins_changed", "pro_plugins_changed", "config_changed", "instances_changed")
|
||||
if k in ("custom_configs_changed", "external_plugins_changed", "pro_plugins_changed", "plugins_config_changed", "instances_changed")
|
||||
):
|
||||
ui_data["PRO_LOADING"] = False
|
||||
with LOCK:
|
||||
|
|
@ -799,8 +799,7 @@ def home():
|
|||
remote_version = basename(r.url).strip().replace("v", "")
|
||||
|
||||
config = app.config["CONFIG"].get_config(with_drafts=True)
|
||||
override_instances = config["OVERRIDE_INSTANCES"]["value"] != ""
|
||||
instances = app.config["INSTANCES"].get_instances(override_instances=override_instances)
|
||||
instances = app.config["INSTANCES"].get_instances()
|
||||
|
||||
instance_health_count = 0
|
||||
|
||||
|
|
@ -919,7 +918,7 @@ def account():
|
|||
if any(
|
||||
v
|
||||
for k, v in db_metadata.items()
|
||||
if k in ("custom_configs_changed", "external_plugins_changed", "pro_plugins_changed", "config_changed", "instances_changed")
|
||||
if k in ("custom_configs_changed", "external_plugins_changed", "pro_plugins_changed", "plugins_config_changed", "instances_changed")
|
||||
):
|
||||
ui_data["RELOADING"] = True
|
||||
ui_data["LAST_RELOAD"] = time()
|
||||
|
|
@ -1259,7 +1258,7 @@ def services():
|
|||
if any(
|
||||
v
|
||||
for k, v in db_metadata.items()
|
||||
if k in ("custom_configs_changed", "external_plugins_changed", "pro_plugins_changed", "config_changed", "instances_changed")
|
||||
if k in ("custom_configs_changed", "external_plugins_changed", "pro_plugins_changed", "plugins_config_changed", "instances_changed")
|
||||
):
|
||||
ui_data = get_ui_data()
|
||||
ui_data["RELOADING"] = True
|
||||
|
|
@ -1388,7 +1387,7 @@ def global_config():
|
|||
if any(
|
||||
v
|
||||
for k, v in db_metadata.items()
|
||||
if k in ("custom_configs_changed", "external_plugins_changed", "pro_plugins_changed", "config_changed", "instances_changed")
|
||||
if k in ("custom_configs_changed", "external_plugins_changed", "pro_plugins_changed", "plugins_config_changed", "instances_changed")
|
||||
):
|
||||
ui_data["RELOADING"] = True
|
||||
ui_data["LAST_RELOAD"] = time()
|
||||
|
|
@ -1590,7 +1589,7 @@ def plugins():
|
|||
if any(
|
||||
v
|
||||
for k, v in db_metadata.items()
|
||||
if k in ("custom_configs_changed", "external_plugins_changed", "pro_plugins_changed", "config_changed", "instances_changed")
|
||||
if k in ("custom_configs_changed", "external_plugins_changed", "pro_plugins_changed", "plugins_config_changed", "instances_changed")
|
||||
):
|
||||
ui_data = get_ui_data()
|
||||
ui_data["RELOADING"] = True
|
||||
|
|
@ -1804,7 +1803,7 @@ def plugins():
|
|||
if any(
|
||||
v
|
||||
for k, v in db_metadata.items()
|
||||
if k in ("custom_configs_changed", "external_plugins_changed", "pro_plugins_changed", "config_changed", "instances_changed")
|
||||
if k in ("custom_configs_changed", "external_plugins_changed", "pro_plugins_changed", "plugins_config_changed", "instances_changed")
|
||||
):
|
||||
ui_data = get_ui_data()
|
||||
ui_data["RELOADING"] = True
|
||||
|
|
|
|||
Loading…
Reference in a new issue