diff --git a/integrator/docker/kestra-init.sh b/integrator/docker/kestra-init.sh index fd821d2..96998d0 100644 --- a/integrator/docker/kestra-init.sh +++ b/integrator/docker/kestra-init.sh @@ -2,8 +2,21 @@ set -e KESTRA_URL="${KESTRA_URL:-http://kestra:8080}" +MAX_WAIT=120 -echo "Importing flows into Kestra at ${KESTRA_URL}..." +echo "Waiting for Kestra API at ${KESTRA_URL}..." +elapsed=0 +until curl -sf "${KESTRA_URL}/api/v1/flows/search" > /dev/null 2>&1; do + if [ "$elapsed" -ge "$MAX_WAIT" ]; then + echo "ERROR: Kestra API not reachable after ${MAX_WAIT}s" + exit 1 + fi + sleep 5 + elapsed=$((elapsed + 5)) +done +echo "Kestra API is ready." + +echo "Importing flows..." for f in /flows/*.yml; do name="$(basename "$f")" @@ -17,7 +30,6 @@ for f in /flows/*.yml; do if [ "$http_code" = "200" ] || [ "$http_code" = "201" ]; then echo " created" elif [ "$http_code" = "409" ]; then - # Flow already exists — update it via PUT /api/v1/flows/{namespace}/{id} ns=$(grep '^namespace:' "$f" | awk '{print $2}') id=$(grep '^id:' "$f" | awk '{print $2}') http_code2=$(curl -s -o /tmp/kestra_resp -w "%{http_code}" \