mirror of
https://github.com/zephrynis/PluginDownloader.git
synced 2026-02-18 20:11:54 +00:00
Implement dynamic config file monitoring and update checks in main loop
This commit is contained in:
45
main.py
45
main.py
@@ -199,13 +199,36 @@ def main():
|
|||||||
|
|
||||||
logger.info("Starting Plugin Updater...")
|
logger.info("Starting Plugin Updater...")
|
||||||
|
|
||||||
while True:
|
last_config_mtime = 0
|
||||||
config = load_config()
|
last_check_time = 0
|
||||||
if not config:
|
config = None
|
||||||
logger.warning("No config found, sleeping...")
|
|
||||||
time.sleep(60)
|
|
||||||
continue
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
# Check for config file changes
|
||||||
|
try:
|
||||||
|
current_mtime = 0
|
||||||
|
if os.path.exists(CONFIG_FILE):
|
||||||
|
current_mtime = os.path.getmtime(CONFIG_FILE)
|
||||||
|
|
||||||
|
if current_mtime != last_config_mtime:
|
||||||
|
logger.info("Config file changed or initial load. Reloading...")
|
||||||
|
new_config = load_config()
|
||||||
|
if new_config:
|
||||||
|
config = new_config
|
||||||
|
last_config_mtime = current_mtime
|
||||||
|
# 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()
|
state = load_state()
|
||||||
|
|
||||||
for plugin in config.get('plugins', []):
|
for plugin in config.get('plugins', []):
|
||||||
@@ -214,9 +237,13 @@ def main():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error processing {plugin.get('name')}: {e}")
|
logger.error(f"Error processing {plugin.get('name')}: {e}")
|
||||||
|
|
||||||
interval = config.get('check_interval', 3600)
|
last_check_time = time.time()
|
||||||
logger.info(f"Sleeping for {interval} seconds...")
|
logger.info(f"Check complete. Next check in ~{interval} seconds.")
|
||||||
time.sleep(interval)
|
else:
|
||||||
|
if last_config_mtime == 0:
|
||||||
|
logger.warning("Waiting for valid configuration...")
|
||||||
|
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user