Skip to content

Commit

Permalink
fix: Make the logic around last_count working
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jhutar committed Oct 17, 2024
1 parent 2da2f9d commit 8dba97c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ci-scripts/rhdh-setup/create_resource.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 8dba97c

Please sign in to comment.