Files
rpa_vision_v3/docs/guides/AUTOMATION_GUIDE.md
Dom a27b74cf22 v1.0 - Version stable: multi-PC, détection UI-DETR-1, 3 modes exécution
- Frontend v4 accessible sur réseau local (192.168.1.40)
- Ports ouverts: 3002 (frontend), 5001 (backend), 5004 (dashboard)
- Ollama GPU fonctionnel
- Self-healing interactif
- Dashboard confiance

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 11:23:51 +01:00

345 lines
7.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 🤖 Guide d'Automatisation RPA Vision V3
## 🎉 Automatisation Complète Implémentée !
Le système d'automatisation est maintenant **100% fonctionnel** et tourne en arrière-plan 24/7.
---
## 📊 Vue d'Ensemble
### Architecture
```
┌──────────────────────────────────────┐
│ AutomationScheduler (Thread) │
│ Tourne en arrière-plan │
└──────────────────────────────────────┘
├─→ Schedule Triggers
│ └─→ Vérifie toutes les 1s
│ └─→ Lance workflows/chaînes
├─→ File Triggers
│ └─→ Surveille répertoires
│ └─→ Lance sur nouveau fichier
└─→ Manual Triggers
└─→ Via API/Interface
```
### Composants
1. **AutomationScheduler** - Thread background qui vérifie les triggers
2. **ChainManager** - Gère les séquences de workflows
3. **TriggerManager** - Gère les déclencheurs
4. **Métriques Prometheus** - Suivi des exécutions
---
## 🚀 Utilisation
### 1. Créer une Chaîne Automatique
**Scénario : Backup quotidien automatique**
```python
from core.monitoring import AutomationScheduler
from core.monitoring.chain_manager import ChainManager
from core.monitoring.trigger_manager import TriggerManager
from pathlib import Path
# Initialiser les managers
cm = ChainManager(Path('data/chains'))
tm = TriggerManager(Path('data/triggers'))
# Créer une chaîne
chain = cm.create_chain(
name="Backup Quotidien",
workflows=["wf_export", "wf_compress", "wf_upload"]
)
# Créer un trigger schedule pour cette chaîne
trigger = tm.create_trigger(
trigger_type="schedule",
workflow_id=chain.chain_id, # Pointer vers la chaîne !
config={
"interval_seconds": 86400 # 24 heures
}
)
print(f"✅ Chaîne {chain.chain_id} créée")
print(f"✅ Trigger {trigger.trigger_id} créé")
print("🤖 Le backup se lancera automatiquement toutes les 24h")
```
### 2. Créer un Trigger File
**Scénario : Traiter automatiquement les factures**
```python
# Créer un trigger qui surveille un dossier
trigger = tm.create_trigger(
trigger_type="file",
workflow_id="wf_process_invoice",
config={
"watch_directory": "/tmp/invoices",
"file_pattern": "*.pdf"
}
)
print("✅ Trigger file créé")
print("🤖 Chaque PDF dans /tmp/invoices lancera le workflow")
```
### 3. Via l'Interface Admin
1. **Accéder** : http://localhost:5001
2. **Onglet "Chaînes"** :
- Cliquer " Nouvelle Chaîne"
- Sélectionner les workflows
- Sauvegarder
3. **Onglet "Déclencheurs"** :
- Cliquer " Nouveau Déclencheur"
- Choisir le type (schedule/file)
- Configurer
- Activer
4. **Onglet "Métriques"** :
- Voir le statut de l'automatisation
- Démarrer/Arrêter le scheduler
- Voir les triggers actifs
---
## ⚙️ Configuration
### Démarrage Automatique
Le scheduler démarre automatiquement avec le dashboard :
```python
# Dans web_dashboard/app.py
automation_scheduler = AutomationScheduler(
trigger_manager=trigger_manager,
chain_manager=chain_manager,
check_interval=1.0 # Vérifier toutes les secondes
)
automation_scheduler.start()
```
### Contrôle via API
```bash
# Vérifier le statut
curl http://localhost:5001/api/automation/status
# Démarrer
curl -X POST http://localhost:5001/api/automation/start
# Arrêter
curl -X POST http://localhost:5001/api/automation/stop
```
---
## 📝 Exemples Complets
### Exemple 1 : Monitoring Automatique
```python
# Créer une chaîne de monitoring
chain = cm.create_chain(
name="Health Check",
workflows=["wf_check_disk", "wf_check_memory", "wf_send_report"]
)
# Lancer toutes les heures
trigger = tm.create_trigger(
trigger_type="schedule",
workflow_id=chain.chain_id,
config={"interval_seconds": 3600}
)
```
### Exemple 2 : Traitement de Fichiers
```python
# Créer un workflow de traitement
# (le workflow doit déjà exister)
# Surveiller un dossier
trigger = tm.create_trigger(
trigger_type="file",
workflow_id="wf_process_csv",
config={
"watch_directory": "/data/imports",
"file_pattern": "*.csv"
}
)
```
### Exemple 3 : Chaîne Complexe
```python
# Créer une chaîne multi-étapes
chain = cm.create_chain(
name="Process Complet",
workflows=[
"wf_login",
"wf_download_data",
"wf_transform",
"wf_upload",
"wf_logout"
]
)
# Lancer tous les jours à minuit (86400 secondes)
trigger = tm.create_trigger(
trigger_type="schedule",
workflow_id=chain.chain_id,
config={"interval_seconds": 86400}
)
```
---
## 🔍 Monitoring
### Logs
Tous les événements sont loggés :
```bash
# Voir les logs du scheduler
tail -f logs/automation_scheduler.log
# Voir les logs des chaînes
tail -f logs/chain_manager.log
# Voir les logs des triggers
tail -f logs/trigger_manager.log
```
### Métriques Prometheus
```bash
# Voir les métriques
curl http://localhost:5001/metrics | grep trigger
# Exemples de métriques :
# trigger_fires_total{trigger_type="schedule",workflow_id="chain_001"} 42
# chain_executions_total{chain_id="chain_001",status="success"} 40
# workflow_duration_seconds{workflow_id="wf_login"} 5.2
```
### Interface Admin
Onglet **Métriques** :
- 🟢 Statut du scheduler (Actif/Arrêté)
- 📊 Nombre de triggers actifs
- ⏱️ Intervalle de vérification
- 🔄 Bouton Démarrer/Arrêter
---
## 🛠️ Dépannage
### Le scheduler ne démarre pas
```python
# Vérifier le statut
import requests
r = requests.get('http://localhost:5001/api/automation/status')
print(r.json())
# Démarrer manuellement
r = requests.post('http://localhost:5001/api/automation/start')
print(r.json())
```
### Les triggers ne se déclenchent pas
```python
# Vérifier que le trigger est activé
trigger = tm.get_trigger('trigger_001')
print(f"Enabled: {trigger.enabled}")
# Activer si nécessaire
tm.enable_trigger('trigger_001')
# Vérifier la config
print(f"Config: {trigger.config}")
```
### Les chaînes échouent
```python
# Vérifier l'historique
chain = cm.get_chain('chain_001')
print(f"Success rate: {chain.success_rate}%")
print(f"Last execution: {chain.last_execution}")
print(f"History: {chain.execution_history[-5:]}") # 5 dernières
```
---
## 📊 Comportement
### Schedule Triggers
- ✅ Vérifie toutes les **1 seconde**
- ✅ Lance si **interval écoulé**
- ✅ Met à jour **last_fired**
- ✅ Incrémente **métriques Prometheus**
### File Triggers
- ✅ Vérifie toutes les **1 seconde**
- ✅ Détecte **nouveaux fichiers**
- ✅ Lance **un workflow par fichier**
- ✅ Mémorise **fichiers traités** (évite doublons)
### Chaînes
- ✅ Exécution **séquentielle**
-**Arrêt sur échec**
-**Historique** sauvegardé
-**Taux de succès** calculé
---
## 🎯 Cas d'Usage
### 1. Backup Automatique
- Chaîne : Export → Compress → Upload
- Trigger : Schedule (quotidien)
### 2. Traitement de Fichiers
- Workflow : Process CSV
- Trigger : File (*.csv)
### 3. Monitoring Continu
- Chaîne : Check → Alert → Report
- Trigger : Schedule (horaire)
### 4. Workflow Nocturne
- Chaîne : Cleanup → Backup → Report
- Trigger : Schedule (minuit)
---
## ✨ Résumé
**Scheduler automatique** - Tourne 24/7 en arrière-plan
**Schedule triggers** - Intervalles configurables
**File triggers** - Surveillance de répertoires
**Chaînes automatiques** - Séquences de workflows
**Logs complets** - Tous les événements tracés
**Métriques Prometheus** - Monitoring temps réel
**Interface admin** - Contrôle visuel
**API REST** - Contrôle programmatique
**L'automatisation est maintenant complète et opérationnelle !** 🚀