#!/bin/bash
set -e

# Wait for prefect server to be ready
echo "Waiting for Prefect server..."
until python -c "import urllib.request; urllib.request.urlopen('http://prefect-server:4200/api/health', timeout=2)" 2>/dev/null; do
    echo "Prefect server not ready, waiting..."
    sleep 2
done
echo "Prefect server is ready!"

# Start serving the flow
# serve() creates deployment and listens for runs (no worker needed)
echo "Starting flow server..."
cd /app/flows
exec python deploy.py
