Implement dynamic config file monitoring and update checks in main loop

This commit is contained in:
2026-01-19 19:29:05 +00:00
parent cbdd54a4eb
commit edd783da9b

57
main.py
View File

@@ -199,24 +199,51 @@ def main():
logger.info("Starting Plugin Updater...") logger.info("Starting Plugin Updater...")
last_config_mtime = 0
last_check_time = 0
config = None
while True: while True:
config = load_config() # Check for config file changes
if not config: try:
logger.warning("No config found, sleeping...") current_mtime = 0
time.sleep(60) if os.path.exists(CONFIG_FILE):
continue current_mtime = os.path.getmtime(CONFIG_FILE)
state = load_state() if current_mtime != last_config_mtime:
logger.info("Config file changed or initial load. Reloading...")
for plugin in config.get('plugins', []): new_config = load_config()
try: if new_config:
process_plugin(plugin, state) config = new_config
except Exception as e: last_config_mtime = current_mtime
logger.error(f"Error processing {plugin.get('name')}: {e}") # Force an immediate check on config change
last_check_time = 0
else:
logger.warning("Config file found but failed to load or is empty.")
except Exception as e:
logger.error(f"Error checking config file: {e}")
if config:
interval = config.get('check_interval', 3600)
# Check if it's time to run updates
if time.time() - last_check_time >= interval:
state = load_state()
interval = config.get('check_interval', 3600) for plugin in config.get('plugins', []):
logger.info(f"Sleeping for {interval} seconds...") try:
time.sleep(interval) process_plugin(plugin, state)
except Exception as e:
logger.error(f"Error processing {plugin.get('name')}: {e}")
last_check_time = time.time()
logger.info(f"Check complete. Next check in ~{interval} seconds.")
else:
if last_config_mtime == 0:
logger.warning("Waiting for valid configuration...")
time.sleep(5)
if __name__ == "__main__": if __name__ == "__main__":
main() main()