Retry periodique email + spool galerie en cas de coupure internet

- Spool galerie booth : si upload echoue, photo stockee dans
  data/booth_spool.json et retentee toutes les 5 min
- Email spool : retry periodique (5 min) au lieu de juste au demarrage
- Les deux spools traites dans la meme boucle async
- Message frontend spool : "sera envoyee des que possible"

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-09-18 10:05:21 +02:00
parent 5c774babbb
commit d21d87347d
4 changed files with 119 additions and 15 deletions

View File

@@ -178,18 +178,34 @@ def envoyer_rapport_spool(nb_envoyes: int, destinataires: list[str], nb_echoues:
log.error(f"Erreur envoi rapport spool : {e}")
RETRY_INTERVAL = 300 # 5 minutes
async def tache_spool_periodique():
"""Retente emails + galerie en spool toutes les 5 min."""
from backend.destinations import traiter_booth_spool, taille_booth_spool
await asyncio.sleep(15)
while True:
loop = asyncio.get_event_loop()
# Emails
total_mail = taille_spool()
if total_mail > 0:
log.info(f"Spool email: retry ({total_mail} en attente)")
nb, dests = await loop.run_in_executor(None, traiter_spool)
if nb > 0:
echoues = total_mail - nb
await loop.run_in_executor(None, envoyer_rapport_spool, nb, dests, echoues)
# Galerie booth
total_booth = taille_booth_spool()
if total_booth > 0:
log.info(f"Spool galerie: retry ({total_booth} en attente)")
await loop.run_in_executor(None, traiter_booth_spool)
await asyncio.sleep(RETRY_INTERVAL)
async def tache_spool_demarrage():
"""Tente de vider le spool une seule fois au demarrage du serveur."""
await asyncio.sleep(10)
total = taille_spool()
if total > 0:
log.info(f"Spool: tentative d'envoi au demarrage ({total} en attente)")
nb, dests = await asyncio.get_event_loop().run_in_executor(None, traiter_spool)
if nb > 0:
echoues = total - nb
await asyncio.get_event_loop().run_in_executor(
None, envoyer_rapport_spool, nb, dests, echoues
)
"""Alias pour compatibilite — lance la boucle periodique."""
await tache_spool_periodique()
FICHIER_EMAILS = RACINE / "data" / "emails_history.json"