#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=lib.sh
source "${SCRIPT_DIR}/lib.sh"

CONFIG_PATH="${1:-/workspace/mvp/configs/dev.yaml}"
TASKSPEC_PATH="${2:-}"

if [[ -z "${TASKSPEC_PATH}" ]]; then
  echo "usage: $0 <config_yaml_in_container> <taskspec_yaml_in_container>" >&2
  echo "example: $0 /workspace/mvp/configs/dev.yaml /workspace/mvp/taskspecs/ppo.yaml" >&2
  exit 1
fi

echo "[head] submit via Ray Python SDK"
dexec "${HEAD_CONTAINER}" bash -lc "cd /workspace/mvp/py && python3 -m argus.cli.run --config '${CONFIG_PATH}' --taskspec '${TASKSPEC_PATH}' --action submit --no-wait"
