# Crontab Serveur — Lead Pipeline

> Serveur : `egrfkmjgnbmqfcbbce@163.172.71.169`
> Installer avec `sudo crontab -e` (copier le bloc ci-dessous)

## Variables

```bash
LEAD_DIR=/home/egrfkmjgnbmqfcbbce/Lead-generator
LOG_DIR=/home/egrfkmjgnbmqfcbbce/Lead-generator/data/logs
```

## Flow journalier

```
05:00  clean-statuses     Nettoie les statuts orphelins
06:00  git pull           Récupère le code à jour
06:00  run-auto           Discovery → Baserow (1er batch)
08:00  sync-espo          Baserow → EspoCRM
08:30  enrich-names       Enrichit les noms de dirigeants
09:30  find-emails        Cherche les emails (permutations SMTP)
12:00  run-auto           Discovery → Baserow (2e batch)
14:00  sync-espo          Baserow → EspoCRM
14:30  enrich-names       Enrichit les noms de dirigeants
15:30  find-emails        Cherche les emails (permutations SMTP)
18:00  git pull           Récupère le code à jour
22:00  sync-resend       Resend events → Dead/Contacted
03:00  cache cleanup      Nettoie le cache Firecrawl (1j/2)
```

## Crontab complet

```crontab
# ============================================================
# Lead Pipeline — Crontab serveur
# Ordre : clean → discovery → sync-espo → enrich-names → find-emails → bounces
# ============================================================

LEAD_DIR=/home/egrfkmjgnbmqfcbbce/Lead-generator
LOG_DIR=/home/egrfkmjgnbmqfcbbce/Lead-generator/data/logs

# --- Git pull 2x/jour (6h et 18h) ---
0 6,18 * * * cd $LEAD_DIR && git pull --ff-only >> $LOG_DIR/git-pull.log 2>&1

# --- 1. Clean statuses (5h, avant tout) ---
0 5 * * * cd $LEAD_DIR && uv run pipeline clean-statuses >> $LOG_DIR/cron-clean.log 2>&1

# --- 2. Discovery (6h, 12h) ---
0 6 * * * cd $LEAD_DIR && uv run pipeline run-auto --daily-target 200 --workers 1 --concurrency 3 >> $LOG_DIR/cron-pipeline.log 2>&1
0 12 * * * cd $LEAD_DIR && uv run pipeline run-auto --daily-target 200 --workers 1 --concurrency 3 >> $LOG_DIR/cron-pipeline.log 2>&1

# --- 3. Sync Baserow → EspoCRM (8h, 14h — après discovery) ---
0 8 * * * cd $LEAD_DIR && uv run pipeline sync-espo --limit 500 >> $LOG_DIR/cron-sync.log 2>&1
0 14 * * * cd $LEAD_DIR && uv run pipeline sync-espo --limit 500 >> $LOG_DIR/cron-sync.log 2>&1

# --- 4. Enrich names (8h30, 14h30 — après sync-espo) ---
30 8 * * * cd $LEAD_DIR && uv run pipeline enrich-names >> $LOG_DIR/cron-enrich.log 2>&1
30 14 * * * cd $LEAD_DIR && uv run pipeline enrich-names >> $LOG_DIR/cron-enrich.log 2>&1

# --- 5. Find emails (9h30, 15h30 — après enrich-names) ---
30 9 * * * cd $LEAD_DIR && uv run pipeline find-emails --limit 500 --concurrency 3 >> $LOG_DIR/cron-emails.log 2>&1
30 15 * * * cd $LEAD_DIR && uv run pipeline find-emails --limit 500 --concurrency 3 >> $LOG_DIR/cron-emails.log 2>&1

# --- 6. Sync Resend events → Dead/Contacted (22h, 1x/jour) ---
0 22 * * * cd $LEAD_DIR && uv run pipeline sync-resend >> $LOG_DIR/cron-bounces.log 2>&1

# --- Nettoyage cache Firecrawl (tous les 2 jours, 3h) ---
0 3 */2 * * rm -rf /data/openclaw-data/workspace/.firecrawl/* 2>/dev/null
```

## Diagnostic rapide

```bash
# Vérifier que Reacher répond
curl -s http://localhost:8080/v0/check_email -X POST \
  -H "Content-Type: application/json" \
  -d '{"to_email": "test@google.com"}' | jq .

# Vérifier les containers Docker
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"

# Voir les dernières lignes de chaque log
tail -5 $LOG_DIR/cron-pipeline.log
tail -5 $LOG_DIR/cron-sync.log
tail -5 $LOG_DIR/cron-enrich.log
tail -5 $LOG_DIR/cron-emails.log
tail -5 $LOG_DIR/cron-bounces.log
```
