Handle config reload thread-safe
This commit is contained in:
+14
-6
@@ -27,7 +27,8 @@ class Application:
|
|||||||
config: Configuration dictionary from TOML file.
|
config: Configuration dictionary from TOML file.
|
||||||
config_path: Path to configuration file (for reload).
|
config_path: Path to configuration file (for reload).
|
||||||
"""
|
"""
|
||||||
self.config = config
|
self._config = config
|
||||||
|
self._config_lock = threading.RLock()
|
||||||
self.config_path = config_path
|
self.config_path = config_path
|
||||||
self.password_hasher = argon2.PasswordHasher()
|
self.password_hasher = argon2.PasswordHasher()
|
||||||
self.shutdown_event = threading.Event()
|
self.shutdown_event = threading.Event()
|
||||||
@@ -38,6 +39,12 @@ class Application:
|
|||||||
self.good_limiter = None
|
self.good_limiter = None
|
||||||
self.bad_limiter = None
|
self.bad_limiter = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def config(self):
|
||||||
|
"""Thread-safe config access."""
|
||||||
|
with self._config_lock:
|
||||||
|
return self._config
|
||||||
|
|
||||||
def init_database(self):
|
def init_database(self):
|
||||||
"""Initialize database connection and run migrations."""
|
"""Initialize database connection and run migrations."""
|
||||||
init_database(self.config)
|
init_database(self.config)
|
||||||
@@ -68,12 +75,13 @@ class Application:
|
|||||||
"""
|
"""
|
||||||
new_config = load_config(self.config_path)
|
new_config = load_config(self.config_path)
|
||||||
|
|
||||||
# Preserve DB and bind settings
|
with self._config_lock:
|
||||||
new_config["database"] = self.config["database"]
|
# Preserve DB and bind settings
|
||||||
new_config["daemon"]["host"] = self.config["daemon"]["host"]
|
new_config["database"] = self._config["database"]
|
||||||
new_config["daemon"]["port"] = self.config["daemon"]["port"]
|
new_config["daemon"]["host"] = self._config["daemon"]["host"]
|
||||||
|
new_config["daemon"]["port"] = self._config["daemon"]["port"]
|
||||||
|
|
||||||
self.config = new_config
|
self._config = new_config
|
||||||
|
|
||||||
# Reconfigure logging
|
# Reconfigure logging
|
||||||
setup_logging(
|
setup_logging(
|
||||||
|
|||||||
Reference in New Issue
Block a user