#!/bin/bash
# Script to run the task with a timeout.
# ECS tasks don't have a native timeout so we use this script
# to kill the task if it hangs for some reason.
# The timeout duration can be set with the TIMEOUT_DURATION env var
# otherwise it defaults to 5 hours.

# Exit on first command failed
set -e

DIR="$(cd "$(dirname "$0")" && pwd)"
ROOT_DIR="${DIR}/.."
ENTRYPOINT="${ROOT_DIR}/app.py"

TIMEOUT="${TIMEOUT_DURATION:-5h}"

echo "Running ${ENTRYPOINT} with a ${TIMEOUT} timeout"
timeout $TIMEOUT python $ENTRYPOINT
