Skip to content

Commit

Permalink
fix: run action during interrupt as well (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
DekusDenial authored Oct 20, 2023
1 parent cb6e920 commit 4ace3ad
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions Docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
# Trap these SIGNALs and run teardown
trap 'trap_handler $@' INT TERM

trap_handler () {
code=$?
if [ $code -ne 0 ]; then
echo "Exit code:$code received in run.sh, waiting for $SD_TERMINATION_GRACE_PERIOD_SECONDS seconds"
# this trap does not wait for launcher SIGTERM processing completion
# so add sleep until timeoutgraceperiodseconds is elapsed
sleep $SD_TERMINATION_GRACE_PERIOD_SECONDS
fi
dump_event() {
if [ -r /tmp/sd_event.json ]; then
cat /tmp/sd_event.json
fi
}

trap_handler() {
code=$?
if [ $code -ne 0 ]; then
echo "Exit code:$code received in run.sh, waiting for $SD_TERMINATION_GRACE_PERIOD_SECONDS seconds"
# this trap does not wait for launcher SIGTERM processing completion
# so add sleep until timeoutgraceperiodseconds is elapsed
sleep $((SD_TERMINATION_GRACE_PERIOD_SECONDS - 1))
dump_event
fi
}

# Get push gateway url and container image from env variable
Expand Down Expand Up @@ -42,6 +49,4 @@ else
SD_TOKEN=`/opt/sd/launch --only-fetch-token --token "$1" --api-uri "$2" --store-uri "$3" --ui-uri "$6" --emitter /sd/emitter --build-timeout "$4" --cache-strategy "$7" --pipeline-cache-dir "$8" --job-cache-dir "$9" --event-cache-dir "${10}" --cache-compress "${11}" --cache-md5check "${12}" --cache-max-size-mb "${13}" --cache-max-go-threads "${14}" "$5"` && (/opt/sd/launch --token "$SD_TOKEN" --api-uri "$2" --store-uri "$3" --ui-uri "$6" --emitter /sd/emitter --build-timeout "$4" --cache-strategy "$7" --pipeline-cache-dir "$8" --job-cache-dir "$9" --event-cache-dir "${10}" --cache-compress "${11}" --cache-md5check "${12}" --cache-max-size-mb "${13}" --cache-max-go-threads "${14}" "$5" & /opt/sd/logservice --token "$SD_TOKEN" --emitter /sd/emitter --api-uri "$2" --store-uri "$3" --build "$5" & wait $(jobs -p))
fi

if [ -r /tmp/sd_event.json ]; then
cat /tmp/sd_event.json
fi
dump_event

0 comments on commit 4ace3ad

Please sign in to comment.