Skip to content

Commit 8d1a7dd

Browse files
ci: retry Railway preview service discovery (#2800)
* ci: retry Railway preview service discovery * ci: propagate Railway discovery failures --------- Co-authored-by: Andrew Mikofalvy <5668128+amikofalvy@users.noreply.github.com>
1 parent 8bf717a commit 8d1a7dd

1 file changed

Lines changed: 51 additions & 11 deletions

File tree

.github/scripts/preview/common.sh

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,55 @@ EOF
185185
jq -r --arg service_name "${service_name}" '.data.environment.serviceInstances.edges[] | select(.node.serviceName == $service_name) | .node.serviceId' <<< "${response}"
186186
}
187187

188+
railway_wait_for_environment_id() {
189+
local project_id="$1"
190+
local env_name="$2"
191+
local max_attempts="${3:-30}"
192+
local sleep_seconds="${4:-2}"
193+
local attempt=""
194+
local env_id=""
195+
196+
for attempt in $(seq 1 "${max_attempts}"); do
197+
env_id="$(railway_environment_id "${project_id}" "${env_name}")"
198+
if [ -n "${env_id}" ]; then
199+
printf '%s' "${env_id}"
200+
return 0
201+
fi
202+
203+
if [ "${attempt}" -lt "${max_attempts}" ]; then
204+
sleep_with_jitter "${sleep_seconds}"
205+
fi
206+
done
207+
208+
echo "Unable to resolve Railway environment ID for ${env_name}." >&2
209+
return 1
210+
}
211+
212+
railway_wait_for_service_id_for_env() {
213+
local env_id="$1"
214+
local service_name="$2"
215+
local env_name="$3"
216+
local max_attempts="${4:-30}"
217+
local sleep_seconds="${5:-2}"
218+
local attempt=""
219+
local service_id=""
220+
221+
for attempt in $(seq 1 "${max_attempts}"); do
222+
service_id="$(railway_service_id_for_env "${env_id}" "${service_name}")"
223+
if [ -n "${service_id}" ]; then
224+
printf '%s' "${service_id}"
225+
return 0
226+
fi
227+
228+
if [ "${attempt}" -lt "${max_attempts}" ]; then
229+
sleep_with_jitter "${sleep_seconds}"
230+
fi
231+
done
232+
233+
echo "Unable to resolve Railway service ID for ${service_name} in ${env_name}." >&2
234+
return 1
235+
}
236+
188237
railway_ensure_tcp_proxy() {
189238
local project_id="$1"
190239
local env_name="$2"
@@ -199,17 +248,8 @@ railway_ensure_tcp_proxy() {
199248
local active=""
200249
local attempt=""
201250

202-
env_id="$(railway_environment_id "${project_id}" "${env_name}")"
203-
if [ -z "${env_id}" ]; then
204-
echo "Unable to resolve Railway environment ID for ${env_name}." >&2
205-
return 1
206-
fi
207-
208-
service_id="$(railway_service_id_for_env "${env_id}" "${service_name}")"
209-
if [ -z "${service_id}" ]; then
210-
echo "Unable to resolve Railway service ID for ${service_name} in ${env_name}." >&2
211-
return 1
212-
fi
251+
env_id="$(railway_wait_for_environment_id "${project_id}" "${env_name}" "${max_attempts}" "${sleep_seconds}")" || return 1
252+
service_id="$(railway_wait_for_service_id_for_env "${env_id}" "${service_name}" "${env_name}" "${max_attempts}" "${sleep_seconds}")" || return 1
213253

214254
response="$(
215255
railway_graphql "$(cat <<EOF

0 commit comments

Comments
 (0)