Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

fix: silent spot instance cancelling #17

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Changes from 1 commit
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
19 changes: 11 additions & 8 deletions scripts/spot_run_script
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
# 2... ARGS: Arguments to pass to remote_run_script.
set -e

# On any sort of exit (error or not), kill spot request so it doesn't count against quota.
function on_exit {
if [ -f "sir-$COMMIT_HASH:$JOB_NAME.txt" ]; then
SIR=$(cat sir-$COMMIT_HASH:$JOB_NAME.txt)
echo "Cancelling spot instance request $SIR (silently)"
aws ec2 cancel-spot-instance-requests --spot-instance-request-ids $SIR 2>&1 > /dev/null || true
fi
}
trap on_exit EXIT

SPEC=$1
shift

Expand All @@ -19,11 +29,4 @@ CODE=$?
echo "Terminating spot instance..."
ssh -F $SSH_CONFIG_PATH $IP sudo halt -p > /dev/null 2>&1

# Kill spot request so it doesn't count against quota.
if [ -f "sir-$COMMIT_HASH:$JOB_NAME.txt" ]; then
SIR=$(cat sir-$COMMIT_HASH:$JOB_NAME.txt)
echo "Cancelling spot instance request $SIR"
aws ec2 cancel-spot-instance-requests --spot-instance-request-ids $SIR > /dev/null
fi

exit $CODE
exit $CODE