From 18e48a2ba1a06a8c59e993deae64916da9a9f56f Mon Sep 17 00:00:00 2001 From: Andre Challier Date: Mon, 12 Jan 2026 08:57:46 +0100 Subject: [PATCH] Added retry-loop to init script --- webhooks-git/dadi-staging-init.sh | 51 +++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/webhooks-git/dadi-staging-init.sh b/webhooks-git/dadi-staging-init.sh index fcfaaab..83888b6 100644 --- a/webhooks-git/dadi-staging-init.sh +++ b/webhooks-git/dadi-staging-init.sh @@ -10,6 +10,57 @@ HTML_HOME="/html" BRANCHES_FOLDER="/html/branches" DADI_STAGING_REPOSITORY="git_dadi-staging:AG-IT/KlDaDiSeite.git" +MAX_RETRY_ATTEMPTS=${INIT_RETRY_ATTEMPTS:--1} +RETRY_DELAY=${INIT_RETRY_DELAY:-2} + +# +# Funktion: Warte bis Git-Repository erreichbar ist +# +wait_for_git_repository() { + local attempt=0 + local unlimited=false + + # Prüfe ob unbegrenzte Retries gewünscht sind + if [ $MAX_RETRY_ATTEMPTS -lt 0 ]; then + unlimited=true + echo "Checking Git repository availability (unlimited retries)..." + else + echo "Checking Git repository availability (max $MAX_RETRY_ATTEMPTS attempts)..." + fi + + while true; do + if git ls-remote --heads "$DADI_STAGING_REPOSITORY" &>/dev/null; then + echo "✓ Git repository is reachable!" + return 0 + fi + + attempt=$((attempt + 1)) + + if [ "$unlimited" = true ]; then + echo "⏳ Waiting for Git repository... (attempt $attempt)" + else + echo "⏳ Waiting for Git repository... (attempt $attempt/$MAX_RETRY_ATTEMPTS)" + + # Abbruch bei Erreichen des Limits + if [ $attempt -ge $MAX_RETRY_ATTEMPTS ]; then + echo "✗ Error: Could not reach Git repository after $MAX_RETRY_ATTEMPTS attempts" + return 1 + fi + fi + + sleep $RETRY_DELAY + done +} + +# +# Warte auf Git-Repository +# +if ! wait_for_git_repository; then + echo "Initialization failed. Service will continue but branches won't be initialized." + echo "You may need to manually trigger initialization or restart the service." + exit 1 +fi + # # Remove all branch folders #