Skip to content

Commit

Permalink
Merge pull request #119 from Aiven-Open/rauli-reload-config-in-main-loop
Browse files Browse the repository at this point in the history
Reload config on main thread
  • Loading branch information
rdunklau authored Mar 13, 2024
2 parents 408217a + 67d96f4 commit 7c5e53c
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pglookout/pglookout.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ def __init__(self, config_path):
self._config_version_applied = 0
self._failover_on_disconnect = True
self.load_config()
self.config_reload_pending = False

signal.signal(signal.SIGHUP, self.load_config)
signal.signal(signal.SIGHUP, self.sighup)
signal.signal(signal.SIGINT, self.quit)
signal.signal(signal.SIGTERM, self.quit)

Expand Down Expand Up @@ -101,18 +102,21 @@ def __init__(self, config_path):

def quit(self, _signal=None, _frame=None):
self.log.warning("Quitting, signal: %r, frame: %r", _signal, _frame)
self.cluster_monitor.running = False
if self.cluster_monitor:
self.cluster_monitor.running = False
self.running = False
self.webserver.close()

def load_config(self, _signal=None, _frame=None):
def sighup(self, _signal=None, _frame=None):
self.log.debug(
"Loading JSON config from: %r, signal: %r, frame: %r",
self.config_path,
"Requesting config re-load (signal: %r, frame: %r)",
_signal,
_frame,
)
self.config_reload_pending = True

def load_config(self):
self.log.debug("Loading JSON config from: %r", self.config_path)
previous_remote_conns = self.config.get("remote_conns")
try:
with open(self.config_path) as fp:
Expand Down Expand Up @@ -854,6 +858,9 @@ def _get_check_interval(self) -> float:

def main_loop(self):
while self.running:
if self.config_reload_pending:
self.load_config()
self.config_reload_pending = False
try:
self._apply_latest_config_version()
except Exception as ex: # pylint: disable=broad-except
Expand Down

0 comments on commit 7c5e53c

Please sign in to comment.