#!/usr/bin/env bash
# Every job starts here, so a systemd unit never hardcodes an interpreter.
#
#   bin/run-job tg_bridge     runs `python -m jobs.tg_bridge` from the repo root
set -euo pipefail

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

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

# Prefer the repo'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
    PYTHON="$(command -v python3)"
fi

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