#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" CONTROL_DIR="$ROOT_DIR/tests/golden/WBV2" SCHEDULER_MAX_ITERATIONS="${WBV2_MAX_ITERATIONS:-0}" SCHEDULER_POLL_MS="${WBV2_POLL_MS:-1000}" SCHEDULER_PUSH_RETRIES="${WBV2_PUSH_RETRIES:-6}" WATCHDOG_INTERVAL="${WBV2_WATCHDOG_INTERVAL:-10}" WATCHDOG_RESTART_DELAY="${WBV2_WATCHDOG_RESTART_DELAY:-5}" mkdir -p "$CONTROL_DIR" start_scheduler() { local pid_file="$CONTROL_DIR/my-tools-scheduler.pid" if test -f "$pid_file"; then local scheduler_pid scheduler_pid="$(tr -d '[:space:]' < "$pid_file")" if test -n "$scheduler_pid" && kill -0 "$scheduler_pid" 2>/dev/null; then printf 'scheduler already running: %s\n' "$scheduler_pid" return fi rm -f "$pid_file" fi nohup setsid python3 "$ROOT_DIR/my-tools/run_blender_web_scheduler.py" \ --max-iterations "$SCHEDULER_MAX_ITERATIONS" \ --poll-ms "$SCHEDULER_POLL_MS" \ --push-retries "$SCHEDULER_PUSH_RETRIES" \ --commit --push \ > "$CONTROL_DIR/my-tools-scheduler.stdout.log" 2>&1 < /dev/null & printf 'scheduler launch pid: %s\n' "$!" } start_watchdog() { local pid_file="$CONTROL_DIR/my-tools-watchdog.pid" if test -f "$pid_file"; then local watchdog_pid watchdog_pid="$(tr -d '[:space:]' < "$pid_file")" if test -n "$watchdog_pid" && kill -0 "$watchdog_pid" 2>/dev/null; then printf 'watchdog already running: %s\n' "$watchdog_pid" return fi rm -f "$pid_file" fi nohup setsid python3 "$ROOT_DIR/my-tools/watch_blender_web_scheduler.py" \ --interval "$WATCHDOG_INTERVAL" \ --restart-delay "$WATCHDOG_RESTART_DELAY" \ --max-iterations "$SCHEDULER_MAX_ITERATIONS" \ --push-retries "$SCHEDULER_PUSH_RETRIES" \ --commit --push \ > "$CONTROL_DIR/my-tools-watchdog.stdout.log" 2>&1 < /dev/null & printf 'watchdog launch pid: %s\n' "$!" } start_scheduler start_watchdog