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

head_ip_file="${ARGUS_HEAD_IP_FILE:?missing ARGUS_HEAD_IP_FILE}"
node_ip="${ARGUS_NODE_IP:?missing ARGUS_NODE_IP}"
poll_s="${ARGUS_POLL_S:-5}"

resources_kv="${ARGUS_WORKER_RESOURCES_KV:-worker_node=100}"

args=()
IFS=',' read -r -a parts <<<"${resources_kv}"
for kv in "${parts[@]}"; do
  kv="$(echo "${kv}" | xargs || true)"
  [[ -z "${kv}" ]] && continue
  args+=( "--resources-kv" "${kv}" )
done

exec python3 -m argus.ray.worker_watchdog \
  --head-ip-file "${head_ip_file}" \
  --node-ip "${node_ip}" \
  "${args[@]}" \
  --poll-s "${poll_s}" \
  --ray-start-block

