From 377d47eca27907e5720432b0bcb419482bd4b8ed Mon Sep 17 00:00:00 2001 From: Tudor Date: Tue, 24 Mar 2026 19:47:07 +0000 Subject: [PATCH] fix(kestra-init): add API readiness wait loop before importing flows Waits up to 120s for /api/v1/flows/search to respond before attempting imports, giving a clearer error if the URL is wrong or kestra isn't up. Co-Authored-By: Claude Sonnet 4.6 --- integrator/docker/kestra-init.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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}" \