feat: auto-stop enregistrement (1h) + packaging Léa collaborateurs
- Auto-stop : notification 10 min avant, arrêt automatique après MAX_SESSION_DURATION_S (1h) - Lea.bat : kill des anciens process (python, pythonw, rpa-agent) au démarrage - LISEZMOI : simplifié pour les collaborateurs (pas de replay, juste collecte) - Chat server (5004) vérifié fonctionnel Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -16,7 +16,7 @@ import logging
|
||||
import threading
|
||||
from .config import (
|
||||
SESSIONS_ROOT, AGENT_VERSION, SERVER_URL, MACHINE_ID, LOG_RETENTION_DAYS,
|
||||
SCREEN_RESOLUTION, DPI_SCALE, OS_THEME, API_TOKEN,
|
||||
SCREEN_RESOLUTION, DPI_SCALE, OS_THEME, API_TOKEN, MAX_SESSION_DURATION_S,
|
||||
)
|
||||
from .core.captor import EventCaptorV1
|
||||
from .core.executor import ActionExecutorV1
|
||||
@@ -136,6 +136,58 @@ class AgentV1:
|
||||
time.sleep(30)
|
||||
self.storage.run_auto_cleanup()
|
||||
|
||||
def _auto_stop_loop(self):
|
||||
"""Auto-stop de l'enregistrement après MAX_SESSION_DURATION_S.
|
||||
|
||||
L'utilisateur peut oublier d'arrêter. On notifie à 50 min,
|
||||
puis on arrête automatiquement à 60 min (configurable).
|
||||
"""
|
||||
warn_before = 600 # Prévenir 10 min avant la fin
|
||||
warned = False
|
||||
|
||||
while self.running and self.session_id:
|
||||
elapsed = time.time() - self._session_start_time
|
||||
remaining = MAX_SESSION_DURATION_S - elapsed
|
||||
|
||||
# Notification 10 min avant la fin
|
||||
if not warned and remaining <= warn_before:
|
||||
warned = True
|
||||
mins = int(remaining / 60)
|
||||
logger.info(f"Auto-stop dans {mins} min")
|
||||
try:
|
||||
from .ui.notifications import NotificationManager
|
||||
NotificationManager().notify(
|
||||
"Léa",
|
||||
f"L'enregistrement s'arrêtera automatiquement dans {mins} minutes.",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Auto-stop
|
||||
if remaining <= 0:
|
||||
logger.info(
|
||||
f"Auto-stop : session {self.session_id} après "
|
||||
f"{int(elapsed)}s ({int(elapsed/60)} min)"
|
||||
)
|
||||
try:
|
||||
from .ui.notifications import NotificationManager
|
||||
NotificationManager().notify(
|
||||
"Léa",
|
||||
f"Enregistrement terminé automatiquement après "
|
||||
f"{int(elapsed/60)} minutes. Merci !",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Arrêter via l'état partagé (synchronise systray + chat)
|
||||
if self._state is not None:
|
||||
self._state.stop_recording()
|
||||
else:
|
||||
self.stop_session()
|
||||
break
|
||||
|
||||
time.sleep(30) # Vérifier toutes les 30s
|
||||
|
||||
def start_session(self, workflow_name):
|
||||
self.session_id = f"sess_{time.strftime('%Y%m%dT%H%M%S')}_{uuid.uuid4().hex[:6]}"
|
||||
self.session_dir = self.storage.get_session_dir(self.session_id)
|
||||
@@ -157,6 +209,11 @@ class AgentV1:
|
||||
# Heartbeat Contextuel (Toutes les 5s par defaut)
|
||||
threading.Thread(target=self._heartbeat_loop, daemon=True).start()
|
||||
|
||||
# Auto-stop : arrêter l'enregistrement après MAX_SESSION_DURATION_S
|
||||
# L'utilisateur peut oublier d'arrêter — on le fait automatiquement
|
||||
self._session_start_time = time.time()
|
||||
threading.Thread(target=self._auto_stop_loop, daemon=True).start()
|
||||
|
||||
# Watchdog de Commandes (GHOST Replay — legacy fichier)
|
||||
threading.Thread(target=self._command_watchdog_loop, daemon=True).start()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user