diff --git a/modules/model_updater.py b/modules/model_updater.py index 041b472..5d59972 100644 --- a/modules/model_updater.py +++ b/modules/model_updater.py @@ -6,6 +6,7 @@ import time from modules.logger import log_event CATALOGUE_FILE = "/DATA/AppData/MULTI-IA-AETHAS38/catalogue_dynamique.json" +LOCK_FILE = "/DATA/AppData/MULTI-IA-AETHAS38/updater_lock.txt" def recuperer_modeles_hf(): """ @@ -43,6 +44,27 @@ def recuperer_modeles_hf(): return hf_models def _do_update(): + # --- SYSTÈME ANTI-SPAM (VERROU INTER-PROCESSUS) --- + now = time.time() + try: + if os.path.exists(LOCK_FILE): + with open(LOCK_FILE, "r") as f: + last_update = float(f.read().strip()) + # Si la dernière MAJ date de moins d'une heure (3600 sec), on annule l'exécution de ce thread + if now - last_update < 3600: + return + except Exception: + pass # En cas d'erreur de lecture, on force la MAJ + + # On pose le verrou avec le timestamp actuel pour bloquer les autres workers + try: + os.makedirs(os.path.dirname(LOCK_FILE), exist_ok=True) + with open(LOCK_FILE, "w") as f: + f.write(str(now)) + except Exception as e: + log_event("WARNING", "UPDATER", f"Impossible d'écrire le verrou : {e}") + # --- FIN DU SYSTÈME ANTI-SPAM --- + ollama_host = os.getenv("OLLAMA_HOST", "http://192.168.1.20:11434") try: # MAJ locale Abliterated @@ -87,12 +109,16 @@ def _do_update(): log_event("ERROR", "UPDATER", f"Erreur lors de la MAJ auto : {e}") def trigger_update_now(): + # Force la mise à jour en supprimant le verrou au préalable + if os.path.exists(LOCK_FILE): + try: os.remove(LOCK_FILE) + except: pass threading.Thread(target=_do_update, daemon=True).start() def update_models_background(): - _do_update() + # Boucle de fond while True: - time.sleep(7200) # Attente 2 heures _do_update() + time.sleep(7200) # Attente 2 heures threading.Thread(target=update_models_background, daemon=True).start() \ No newline at end of file