Files
workinf_Blender_Wasm/my-tools/start_unattended.sh
mes123456 0bbe442c41
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
feat(web): keep unattended watcher alive at empty queue
2026-09-03 13:54:14 +08:00

80 lines
2.8 KiB
Bash
Executable File

#!/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}"
AUTO_AUTHORIZE="${WBV2_AUTO_AUTHORIZE:-1}"
WAIT_ON_EMPTY="${WBV2_WAIT_ON_EMPTY:-1}"
# Keep repository evidence on disk while placing compiler/transient caches in
# RAM. Eight compile jobs is the repository's stability limit.
if test -d /dev/shm && test -w /dev/shm; then
export WEB_RAM_CACHE_ROOT="${WEB_RAM_CACHE_ROOT:-/dev/shm/blender-wasm-$(id -u)}"
mkdir -p "$WEB_RAM_CACHE_ROOT/emcache" "$WEB_RAM_CACHE_ROOT/tmp"
export EM_CACHE="${EM_CACHE:-$WEB_RAM_CACHE_ROOT/emcache}"
export TMPDIR="${TMPDIR:-$WEB_RAM_CACHE_ROOT/tmp}"
fi
export CMAKE_BUILD_PARALLEL_LEVEL="${CMAKE_BUILD_PARALLEL_LEVEL:-8}"
export NINJAFLAGS="${NINJAFLAGS:--j8}"
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"
local auto_authorize_args=()
local wait_on_empty_args=()
if test "$AUTO_AUTHORIZE" != "0"; then
auto_authorize_args+=(--auto-authorize)
fi
if test "$WAIT_ON_EMPTY" != "0"; then
wait_on_empty_args+=(--wait-on-empty)
fi
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" \
"${auto_authorize_args[@]}" \
"${wait_on_empty_args[@]}" \
--commit --push \
> "$CONTROL_DIR/my-tools-watchdog.stdout.log" 2>&1 < /dev/null &
printf 'watchdog launch pid: %s\n' "$!"
}
start_scheduler
start_watchdog