#!/bin/bash
# Long-wait monitor - check every 30s for up to 10 minutes
for i in $(seq 1 20); do
    echo "=== CHECK $i ($(date +%H:%M:%S)) ==="
    tail -3 /home/fabian/comfyui8.log
    if ls /home/fabian/ComfyUI/output/bc250_test* 2>/dev/null; then
        echo "*** IMAGE SAVED! ***"
        ls -la /home/fabian/ComfyUI/output/
        exit 0
    fi
    # Check if process still alive
    if ! pgrep -f "python.*main.py" > /dev/null; then
        echo "PROCESS DIED!"
        tail -30 /home/fabian/comfyui8.log
        exit 1
    fi
    sleep 30
done
echo "=== TIMEOUT 10min ==="
tail -30 /home/fabian/comfyui8.log
