#!/bin/sh
set -eu

INTERVAL_SECONDS="${INTERVAL_SECONDS:-2592000}"
RETRY_SECONDS="${RETRY_SECONDS:-3600}"
echo "[start] updater interval=${INTERVAL_SECONDS}s out_dir=${OUT_DIR:-/data}"

while true; do
  echo "[run] update now"
  if python /app/update.py; then
    echo "[sleep] ${INTERVAL_SECONDS}s"
    sleep "${INTERVAL_SECONDS}"
  else
    echo "[warn] update failed; retry in ${RETRY_SECONDS}s"
    sleep "${RETRY_SECONDS}"
  fi
done
