Skip to content

Commit

Permalink
Fix last-launch time query failure behavior
Browse files Browse the repository at this point in the history
If for whatever reason there is a failure in the query or search
for last-launch times, `$latest_launched` could be set to the current
time.  This will ultimately result in no instances being launched.  Fix
this by improved detection of an empty/null launch time in
`${launchtimes[@]}`.

Signed-off-by: Chris Evich <[email protected]>
  • Loading branch information
cevich committed Nov 20, 2023
1 parent d1a3503 commit 723fbf1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mac_pw_pool/LaunchInstances.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,12 @@ if ! $AWS ec2 describe-instances --filters "${pw_filts[@]}" --query "$pw_query"
$(<$inst_lt_f)"
else
declare -a launchtimes
if ! readarray -t launchtimes<<<$(json_query '.[]?' "$inst_lt_f"); then
if ! readarray -t launchtimes<<<$(json_query '.[]?' "$inst_lt_f") ||
[[ "${#launchtimes[@]}" -eq 0 ]] ||
[[ "${launchtimes[0]}" == "" ]]; then
warn "Found no running instances, this should not happen."
else
dbg "launchtimes=[${launchtimes[*]}]"
for launch_time in "${launchtimes[@]}"; do
# Assume launch_time is never malformed
launched_hour=$(date -u -d "$launch_time" "$dcmpfmt")
Expand Down

0 comments on commit 723fbf1

Please sign in to comment.