Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Commit

Permalink
Add configurable retry settings on both in and out
Browse files Browse the repository at this point in the history
  • Loading branch information
adsbooker committed Jun 20, 2019
1 parent bed72b0 commit a2256b7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ Parameters:
* `description` - a short description of the status
* `description_path` - path to an input file whose data is the value of `description`
* `target_url` - the target URL to associate with the status (default: concourse build link)

* `retry_timeout` - the amount of time in seconds to wait while retrying for the status (Default: 3)
* `retry_count` - the number of times to retry for the status to be ready (Default: 5)

## Example

Expand Down
26 changes: 24 additions & 2 deletions bin/in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ eval $( jq -r '{
"version_status": .version.status
} | to_entries[] | .key + "=" + @sh "\(.value)"' < /tmp/stdin )

#
# check retry counter
#

REMAINING_TRIES="${retry_count:-5}"

while true; do

#
# lookup
Expand All @@ -30,9 +37,24 @@ curlgh "$source_endpoint/repos/$source_repository/commits/$version_commit/status
# validate
#

jq -e '.status' < /tmp/status > /dev/null \
|| fatal "Status not found on $( jq -r '.sha' < /tmp/status )"
jq -e '.status' < /tmp/status > /dev/null
check_status="$?"

if [ "$check_status" -eq 0 ]; then
break
elif [ "$check_status" -gt 0 ] && [ "$REMAINING_TRIES" -le 1 ]; then
fatal "Status not found on $( jq -r '.sha' < /tmp/status )"
fi

#
# decrease retry counter and loop
#

REMAINING_TRIES=$(($REMAINING_TRIES - 1))

sleep "${retry_timeout:-3}"

done

#
# concourse
Expand Down
17 changes: 11 additions & 6 deletions bin/out
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ jq -c -n \
# check retry counter
#

REMAINING_TRIES=5
REMAINING_TRIES="${retry_count:-5}"

while [[ $REMAINING_TRIES -gt 0 ]]; do
while true; do

#
# lookup
Expand All @@ -112,17 +112,22 @@ curlgh "$source_endpoint/repos/$source_repository/commits/$source_branch/status"
# validate
#

[[ -s /tmp/status ]] \
&& jq -e '.status' < /tmp/status > /dev/null \
&& break
jq -e '.status' < /tmp/status > /dev/null
check_status="$?"

if [ "$check_status" -eq 0 ]; then
break
elif [ "$check_status" -gt 0 ] && [ "$REMAINING_TRIES" -le 1 ]; then
fatal "Status not found on $( jq -r '.sha' < /tmp/status )"
fi

#
# decrease retry counter and loop
#

REMAINING_TRIES=$(($REMAINING_TRIES - 1))

sleep 1
sleep "${retry_timeout:-3}"

done

Expand Down

0 comments on commit a2256b7

Please sign in to comment.