Skip to content

Instantly share code, notes, and snippets.

@mwvaughn
Last active December 13, 2017 20:02
Show Gist options
  • Save mwvaughn/7f9d25e5b6a0ab688fe80ae5b6be8abc to your computer and use it in GitHub Desktop.
Save mwvaughn/7f9d25e5b6a0ab688fe80ae5b6be8abc to your computer and use it in GitHub Desktop.
Simple Abaco Task Runner
ACTOR_ID=$1
MESSAGE='{"text":"Ma Loute", "icon_emoji": ":love_letter:", "channel": "notifications"}'
if [ -z "${ACTOR_ID}" ]
then
echo "Usage: $(basename $0) [ACTORID]"
exit 1
fi
MAX_ELAPSED=100 # Maximum duration for any async task
INITIAL_PAUSE=1 # Initial delay
BACKOFF=2 # Exponential backoff
TS1=$(date "+%s")
TS2=
ELAPSED=0
PAUSE=${INITIAL_PAUSE}
JOB_STATUS=
export ACTOR_ID
EXEC_ID=$(abaco run -v -m "${MESSAGE}" "${ACTOR_ID}" | jq -r .result.executionId)
export EXEC_ID
echo "Actor ${ACTOR_ID} / Execution ${EXEC_ID} "
while [ "${JOB_STATUS}" != "COMPLETE" ]
do
TS2=$(date "+%s")
ELAPSED=$((${TS2} - ${TS1}))
JOB_STATUS=$(abaco executions -v -e "${EXEC_ID}" "${ACTOR_ID}" | jq -r .result.status)
if [ "${ELAPSED}" -gt "${MAX_ELAPSED}" ]
then
break
fi
printf "Wait " ; printf "%0.s." $(seq 1 ${PAUSE}); printf "\n"
sleep ${PAUSE}
PAUSE=$(($PAUSE * $BACKOFF))
done
echo " ${ELAPSED} seconds"
if [ "${JOB_STATUS}" == "COMPLETE" ]
then
abaco logs -e "${EXEC_ID}" "${ACTOR_ID}"
exit 0
else
echo "Actor ${ACTOR_ID} errored out processing message ${EXEC_ID}"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment