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

Commit a2256b7

Browse files
committed
Add configurable retry settings on both in and out
1 parent bed72b0 commit a2256b7

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ Parameters:
4343
* `description` - a short description of the status
4444
* `description_path` - path to an input file whose data is the value of `description`
4545
* `target_url` - the target URL to associate with the status (default: concourse build link)
46-
46+
* `retry_timeout` - the amount of time in seconds to wait while retrying for the status (Default: 3)
47+
* `retry_count` - the number of times to retry for the status to be ready (Default: 5)
4748

4849
## Example
4950

bin/in

+24-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ eval $( jq -r '{
1111
"version_status": .version.status
1212
} | to_entries[] | .key + "=" + @sh "\(.value)"' < /tmp/stdin )
1313

14+
#
15+
# check retry counter
16+
#
17+
18+
REMAINING_TRIES="${retry_count:-5}"
19+
20+
while true; do
1421

1522
#
1623
# lookup
@@ -30,9 +37,24 @@ curlgh "$source_endpoint/repos/$source_repository/commits/$version_commit/status
3037
# validate
3138
#
3239

33-
jq -e '.status' < /tmp/status > /dev/null \
34-
|| fatal "Status not found on $( jq -r '.sha' < /tmp/status )"
40+
jq -e '.status' < /tmp/status > /dev/null
41+
check_status="$?"
42+
43+
if [ "$check_status" -eq 0 ]; then
44+
break
45+
elif [ "$check_status" -gt 0 ] && [ "$REMAINING_TRIES" -le 1 ]; then
46+
fatal "Status not found on $( jq -r '.sha' < /tmp/status )"
47+
fi
48+
49+
#
50+
# decrease retry counter and loop
51+
#
52+
53+
REMAINING_TRIES=$(($REMAINING_TRIES - 1))
54+
55+
sleep "${retry_timeout:-3}"
3556

57+
done
3658

3759
#
3860
# concourse

bin/out

+11-6
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ jq -c -n \
9191
# check retry counter
9292
#
9393

94-
REMAINING_TRIES=5
94+
REMAINING_TRIES="${retry_count:-5}"
9595

96-
while [[ $REMAINING_TRIES -gt 0 ]]; do
96+
while true; do
9797

9898
#
9999
# lookup
@@ -112,17 +112,22 @@ curlgh "$source_endpoint/repos/$source_repository/commits/$source_branch/status"
112112
# validate
113113
#
114114

115-
[[ -s /tmp/status ]] \
116-
&& jq -e '.status' < /tmp/status > /dev/null \
117-
&& break
115+
jq -e '.status' < /tmp/status > /dev/null
116+
check_status="$?"
117+
118+
if [ "$check_status" -eq 0 ]; then
119+
break
120+
elif [ "$check_status" -gt 0 ] && [ "$REMAINING_TRIES" -le 1 ]; then
121+
fatal "Status not found on $( jq -r '.sha' < /tmp/status )"
122+
fi
118123

119124
#
120125
# decrease retry counter and loop
121126
#
122127

123128
REMAINING_TRIES=$(($REMAINING_TRIES - 1))
124129

125-
sleep 1
130+
sleep "${retry_timeout:-3}"
126131

127132
done
128133

0 commit comments

Comments
 (0)