83 lines
2.8 KiB
Bash
83 lines
2.8 KiB
Bash
#!/bin/bash
|
|
# Pipeline completo com loop de refinamento via Telegram
|
|
# Uso: ./run-pipeline.sh
|
|
# Cron: 30 19 * * * /root/gocode/Jobmaker-LdPost/run-pipeline.sh
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
BIN="$SCRIPT_DIR/bin"
|
|
export LDPOST_WORKSPACE="${LDPOST_WORKSPACE:-$SCRIPT_DIR/workspace}"
|
|
LOG="/tmp/ldpost-pipeline.log"
|
|
|
|
log() { echo "[$(date '+%H:%M:%S')] $*" | tee -a "$LOG"; }
|
|
|
|
exec >> "$LOG" 2>&1
|
|
echo ""
|
|
log "=== PIPELINE START ==="
|
|
|
|
# ── 1. Evaluator: busca trends, envia Telegram, aguarda escolha ───────────────
|
|
log "evaluator: buscando trends e aguardando escolha no Telegram..."
|
|
slug=$("$BIN/ldpost-evaluator")
|
|
if [ -z "$slug" ]; then
|
|
log "ERRO: evaluator não retornou slug"
|
|
exit 1
|
|
fi
|
|
log "slug escolhido: $slug"
|
|
|
|
# ── 2. Redator ────────────────────────────────────────────────────────────────
|
|
log "redator: gerando rascunho..."
|
|
"$BIN/ldpost-redator" --post "$slug"
|
|
|
|
# ── 3. Editor ────────────────────────────────────────────────────────────────
|
|
log "editor: formatando para LinkedIn..."
|
|
"$BIN/ldpost-editor" --post "$slug" --no-interactive
|
|
|
|
# ── 4. Art ───────────────────────────────────────────────────────────────────
|
|
log "art: gerando imagens..."
|
|
"$BIN/ldpost-art" --post "$slug"
|
|
|
|
# ── 5. Loop director + revisões ───────────────────────────────────────────────
|
|
state_file() {
|
|
find "$LDPOST_WORKSPACE" -path "*/$slug/work/state.json" | head -1
|
|
}
|
|
|
|
get_status() {
|
|
local f
|
|
f=$(state_file)
|
|
[ -f "$f" ] && grep -oP '"status":\s*"\K[^"]+' "$f" | head -1
|
|
}
|
|
|
|
while true; do
|
|
log "director: enviando para aprovação no Telegram..."
|
|
"$BIN/ldpost-director" --post "$slug" || true
|
|
|
|
status=$(get_status)
|
|
log "status pós-director: $status"
|
|
|
|
case "$status" in
|
|
waiting_publisher)
|
|
log "Aprovado! Publicando..."
|
|
"$BIN/ldpost-publisher" --post "$slug"
|
|
log "=== PIPELINE CONCLUÍDO ==="
|
|
exit 0
|
|
;;
|
|
rejected)
|
|
log "Post reprovado. Pipeline encerrado."
|
|
exit 0
|
|
;;
|
|
waiting_editor)
|
|
log "Revisão de texto solicitada. Rodando editor..."
|
|
"$BIN/ldpost-editor" --post "$slug" --no-interactive
|
|
;;
|
|
waiting_art)
|
|
log "Revisão de arte solicitada. Rodando art..."
|
|
"$BIN/ldpost-art" --post "$slug"
|
|
;;
|
|
*)
|
|
log "Status inesperado: $status. Encerrando."
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|