From 8dba97c26ad213a2b19e315177f5c5c61f8bc2e1 Mon Sep 17 00:00:00 2001 From: Jan Hutar Date: Fri, 11 Oct 2024 10:13:12 +0200 Subject: [PATCH] fix: Make the logic around `last_count` working Did 2 changes here: First is the important one where I removed `&& [[ $last_count -ge 0 ]]` as that was blocking changing last_count, because it was initialized to -1. Now it should work as expected. Second I made sure warning is printed if we fail to obtain current count value. --- ci-scripts/rhdh-setup/create_resource.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ci-scripts/rhdh-setup/create_resource.sh b/ci-scripts/rhdh-setup/create_resource.sh index e4b94bc..1ef50ff 100755 --- a/ci-scripts/rhdh-setup/create_resource.sh +++ b/ci-scripts/rhdh-setup/create_resource.sh @@ -117,7 +117,7 @@ clone_and_upload() { ACCESS_TOKEN=$(get_token "rhdh") curl -k "$(backstage_url)/api/catalog/locations" --cookie "$COOKIE" --cookie-jar "$COOKIE" -X POST -H 'Accept-Encoding: gzip, deflate, br' -H 'Authorization: Bearer '"$ACCESS_TOKEN" -H 'Content-Type: application/json' --data-raw '{"type":"url","target":"'"${upload_url}"'"}' - timeout=1800 + timeout=300 timeout_timestamp=$(date -d "$timeout seconds" "+%s") last_count=-1 while true; do @@ -128,7 +128,8 @@ clone_and_upload() { ACCESS_TOKEN=$(get_token "rhdh") if [[ 'component-*.yaml' == "${1}" ]]; then b_count=$(curl -s -k "$(backstage_url)/api/catalog/entity-facets?facet=kind" --cookie "$COOKIE" --cookie-jar "$COOKIE" -H 'Content-Type: application/json' -H 'Authorization: Bearer '"$ACCESS_TOKEN" | tee -a "$TMP_DIR/get_component_count.log" | jq -r '.facets.kind[] | select(.value == "Component")| .count'); fi if [[ 'api-*.yaml' == "${1}" ]]; then b_count=$(curl -s -k "$(backstage_url)/api/catalog/entity-facets?facet=kind" --cookie "$COOKIE" --cookie-jar "$COOKIE" -H 'Content-Type: application/json' -H 'Authorization: Bearer '"$ACCESS_TOKEN" | tee -a "$TMP_DIR/get_api_count.log" | jq -r '.facets.kind[] | select(.value == "API")| .count'); fi - if [[ "$last_count" != "$b_count" ]] && [[ $last_count -ge 0 ]]; then # reset the timeout if current count changes + if [[ -z "$b_count" ]]; then log_warn "Failed to get current count, maybe RHDH is down?"; b_count=0; fi + if [[ "$last_count" != "$b_count" ]]; then # reset the timeout if current count changes log_info "The current count changed, resetting entity waiting timeout to $timeout seconds" timeout_timestamp=$(date -d "$timeout seconds" "+%s") last_count=$b_count