#!/usr/bin/env bash
# Every scheduled job starts here, so a systemd unit or crontab line never
# hardcodes an interpreter.
#
#   bin/run-job flight_watch --dry-run
set -euo pipefail

JOB="${1:?usage: run-job <name> [args...]}"
shift

cd "$(dirname "$0")/.."

# Prefer the package's own virtualenv when it exists, so jobs with third-party
# dependencies and jobs without are launched the same way.
if [ -x ".venv/bin/python" ]; then
    PYTHON=".venv/bin/python"
else
    # `python3` from PATH, never /usr/bin/python3 hardcoded: on macOS that is
    # an old system Python that cannot parse modern type hints.
    PYTHON="$(command -v python3)"
fi

exec "$PYTHON" -m "jobs.$JOB" "$@"
