Files
html/api/batch-enrich-async.sh

67 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# Doctrine 169: Cron batch async enrichment - traite 1 page à la fois en fond
# Evite les 502 (pas de charge sur CX endpoint)
# Reprend où il s'est arrêté (idempotent via marker DOCTRINE-60-UX-ENRICH)
LOG=/var/log/batch-enrich-async.log
QUEUE_FILE=/tmp/ux-enrich-queue.txt
# Build queue si inexistante
if [ ! -f "$QUEUE_FILE" ]; then
cat > "$QUEUE_FILE" << 'EOF'
infra-monitor
n8n-hub
paperclip-hub
qdrant-hub
hetzner-hub
docker-hub
github-hub
blade-center
token-health-dashboard
learning-dashboard
cyber-monitor
dormant-dashboard-v2
huggingface-hub
deepseek-hub
universal-integration-hub
qa-hub
wevia-ops-hub
EOF
fi
# Lock (1 instance max)
LOCK=/tmp/batch-enrich.lock
[ -f "$LOCK" ] && exit 0
touch "$LOCK"
trap "rm -f $LOCK" EXIT
# Take first non-enriched from queue
NEXT=""
while IFS= read -r HUB; do
[ -z "$HUB" ] && continue
F="/var/www/html/${HUB}.html"
if [ -f "$F" ] && ! grep -q "DOCTRINE-60-UX-ENRICH" "$F" 2>/dev/null; then
NEXT="$HUB"
break
fi
done < "$QUEUE_FILE"
if [ -z "$NEXT" ]; then
echo "$(date -Iseconds) ALL_DONE" >> "$LOG"
exit 0
fi
# Execute cascade
echo "$(date -Iseconds) START $NEXT" >> "$LOG"
RESULT=$(/var/www/html/api/enrich-hub-cascade.sh "$NEXT" 2>&1 | tail -1)
echo "$(date -Iseconds) $NEXT$RESULT" >> "$LOG"
# Auto-commit si enriched
if echo "$RESULT" | grep -q '"ok":true'; then
cd /var/www/html
sudo -u www-data git add -A >> "$LOG" 2>&1
sudo -u www-data git commit -m "auto(enrich): $NEXT doctrine 60 via cascade async" >> "$LOG" 2>&1 || true
fi
echo "$(date -Iseconds) END $NEXT" >> "$LOG"