#!/usr/bin/env -S bash -e

# Log function
function log {
  printf '[%s] [%s] %s\n' "${0##*/}" "$( date '+%Y-%m-%dT%H:%M:%S' )" "${@}"
}

# Add task scale-in protection (skipped if ECS_AGENT_URI is not set, e.g. local)
if [[ -n "${ECS_AGENT_URI:-}" ]]; then
  log 'Setting task protection'
  curl -X PUT "${ECS_AGENT_URI}/task-protection/v1/state" -d '{"ProtectionEnabled":true, "ExpiresInMinutes":240}'
  log "Current task protection: $(curl -X GET "${ECS_AGENT_URI}/task-protection/v1/state")"
fi
log 'running main.py'
/var/app/venv/bin/ddtrace-run /var/app/venv/bin/python main.py
