Proposition : NeedFinder - Traitement asynchrone via Webhooks
Date : 23/01/2026 23:45
Statut : TERMINÉ ✅
Contexte
- 158,379 posts non traités dans NeedFinder
- Traitement actuel : 25 posts/cycle, polling synchrone (1 à la fois)
- AI-Orchestrator supporte maintenant les webhooks (callback_url)
Objectif
Passer d'un traitement synchrone (polling) à asynchrone (webhooks) pour :
- Traiter plusieurs posts en parallèle
- Ne pas bloquer le scheduler
- Réduire drastiquement le backlog
Modifications
1. NeedFinder - Endpoint webhook
// POST /api/webhook/analysis
// Reçoit le résultat d'un job d'analyse
{
job_id: string,
status: "completed" | "failed",
input_params: { post_id: string, ... },
output_result: { response: string },
error_message?: string
}
2. orchestrator-client.ts - Nouvelle fonction
export async function submitAnalysisJobAsync(
postId: string,
prompt: string,
options: OllamaJobOptions
): Promise<string> {
// Soumet avec callback_url, retourne job_id immédiatement
}
3. analyzer.ts - Mode async
export async function submitAnalysisBatch(limit: number): Promise<number> {
// Soumet N jobs sans attendre, retourne nombre soumis
}
4. scheduler.ts - Batch processing
- Soumettre 100+ jobs par cycle au lieu de 25
- Ne pas attendre les résultats (fire & forget)
- Les résultats arrivent via webhook
Avantages
| Avant |
Après |
| 25 posts/6h |
100+ posts/6h (et traitement continu) |
| Bloquant |
Non-bloquant |
| 1 job à la fois |
N jobs en parallèle |
Risques
- Si webhook échoue → post jamais marqué traité (besoin de retry/fallback)
- Charge sur Ollama si trop de jobs simultanés
Plan d'implémentation
- [x] Proposition créée
- [x] Ajouter endpoint webhook analyse dans index.ts
- [x] Créer fonction submitAnalysisJobAsync
- [x] Modifier analyzer pour mode async
- [x] Ajouter webhook traduction (chaînage auto)
- [x] Ajouter champ analysis_status (pending/submitted/completed/failed)
- [x] Endpoint /api/analyze/all pour traitement complet
- [x] Tester et lancer
Commits : 9bc45a3, c4a9164, 096fd1d, fccbdab
Pipelines : #288, #289, #290, #291