#!/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}" MIGRATION_MODE="${WBV2_MIGRATION_MODE:-product}" # 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 WEB_BUILD_JOBS="${WEB_BUILD_JOBS:-$(WEB_BUILD_MEMORY_GIB_PER_JOB=4 WEB_BUILD_JOBS_CAP=16 bash "$ROOT_DIR/tools/web/compute-build-jobs.sh")}" export WEB_BUILD_JOBS export CMAKE_BUILD_PARALLEL_LEVEL="${CMAKE_BUILD_PARALLEL_LEVEL:-$WEB_BUILD_JOBS}" export NINJAFLAGS="${NINJAFLAGS:--j$WEB_BUILD_JOBS}" 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_product_migration() { python3 "$ROOT_DIR/my-tools/run_web_product_migration.py" start \ --max-cycles "$SCHEDULER_MAX_ITERATIONS" } if test "$MIGRATION_MODE" = "source-verification"; then start_scheduler start_watchdog else start_product_migration fi