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

Add retry parameters and stronger retry logic #15

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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