mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 10:32:57 +01:00
Master landed #4274 with the review changes that came out of it, and those moved the code this branch was built on. Scan job bookkeeping now lives in `handler/scan_jobs.py`, every enqueue goes through `enqueue_task`, cron entries carry their own name and result TTL, and the watcher builds its two rescans from one helper. Resolved by putting this branch's changes where that code now lives: - The scan queue, the scoped-scan check and the second scheduled registry moved into `handler/scan_jobs.py`, keeping master's single-round-trip reads (`get_job_ids` plus one `fetch_many`, and `get_jobs_to_schedule` for the stale sweep) across both registries. - `enqueue_scheduled_scan` sits next to `enqueue_task` in the registry and is built from it, rather than hand-rolling the same enqueue in `tasks/tasks.py`. Its tests moved with it. - Cron keeps master's per-entry name and result TTL, and adds the scan dispatch on top: `TASK_TIMEOUT` for the dispatch, the task's own timeout (now `SCAN_TIMEOUT`) for the scan it enqueues. - The watcher's `schedule_rescan` helper enqueues on the scan queue with the abandoned-job callback. - `PeriodicTask.func` is gone from master, so the scheduled rescan declares only its timeout. `tasks.registry.enqueue_scheduled_scan` joins the func paths an RQ worker has to be able to import. - The job stubs shared by the discovery tests grew the scan queue and a scoped-scan job; the duplicated stale-sweep tests are master's. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
126 lines
3.8 KiB
Bash
126 lines
3.8 KiB
Bash
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
echo "Starting entrypoint script..."
|
|
|
|
# Create symlinks for frontend
|
|
if [[ -L /app/frontend/assets/romm/resources ]]; then
|
|
target=$(readlink "/app/frontend/assets/romm/resources")
|
|
|
|
# If the target is not the same as ${ROMM_BASE_PATH}/resources, recreate the symbolic link.
|
|
if [[ ${target} != "${ROMM_BASE_PATH}/resources" ]]; then
|
|
rm "/app/frontend/assets/romm/resources"
|
|
ln -s "${ROMM_BASE_PATH}/resources" "/app/frontend/assets/romm/resources"
|
|
fi
|
|
elif [[ ! -e /app/frontend/assets/romm/resources ]]; then
|
|
# Ensure parent directory exists before creating symbolic link
|
|
mkdir -p "/app/frontend/assets/romm"
|
|
ln -s "${ROMM_BASE_PATH}/resources" "/app/frontend/assets/romm/resources"
|
|
fi
|
|
|
|
# Define a signal handler to propagate termination signals
|
|
function handle_termination() {
|
|
echo "Terminating child processes..."
|
|
# Kill all background jobs
|
|
# trunk-ignore(shellcheck)
|
|
kill -TERM $(jobs -p) 2>/dev/null
|
|
}
|
|
|
|
# Trap SIGTERM and SIGINT signals
|
|
trap handle_termination SIGTERM SIGINT
|
|
|
|
# Set ROMM_AUTH_SECRET_KEY if not already set
|
|
if [[ -z ${ROMM_AUTH_SECRET_KEY-} ]]; then
|
|
ROMM_AUTH_SECRET_KEY=$(python3 -c "import secrets; print(secrets.token_hex(32))")
|
|
export ROMM_AUTH_SECRET_KEY
|
|
fi
|
|
|
|
# Start all services in the background
|
|
echo "Starting backend..."
|
|
cd /app/backend
|
|
if [[ ${DEV_MODE:-false} == "true" ]]; then
|
|
echo "Starting backend under debugpy on :5678..."
|
|
# Add --wait-for-client after --listen to pause until VSCode attaches.
|
|
uv run python -m debugpy --listen 0.0.0.0:5678 main.py &
|
|
else
|
|
uv run python main.py &
|
|
fi
|
|
|
|
# REDIS_SSL is a boolean to the app, so "false" and "0" mean plaintext.
|
|
REDIS_USERINFO=""
|
|
REDIS_SSL_VALUE="${REDIS_SSL-}"
|
|
case "${REDIS_SSL_VALUE,,}" in
|
|
1 | true | yes | on) REDIS_SCHEME="rediss" ;;
|
|
*) REDIS_SCHEME="redis" ;;
|
|
esac
|
|
if [[ -n ${REDIS_PASSWORD-} ]]; then
|
|
REDIS_USERINFO="${REDIS_USERNAME-}:${REDIS_PASSWORD}@"
|
|
elif [[ -n ${REDIS_USERNAME-} ]]; then
|
|
REDIS_USERINFO="${REDIS_USERNAME}@"
|
|
fi
|
|
REDIS_URL="${REDIS_SCHEME}://${REDIS_USERINFO}${REDIS_HOST:-127.0.0.1}:${REDIS_PORT:-6379}/${REDIS_DB:-0}"
|
|
|
|
echo "Starting RQ cron scheduler..."
|
|
# The URL carries the password, so it goes through RQ_REDIS_URL rather than
|
|
# --url, which would put it on a world-readable command line.
|
|
PYTHONPATH="/app/backend:${PYTHONPATH-}" \
|
|
RQ_REDIS_URL="${REDIS_URL}" \
|
|
rq cron \
|
|
--path /app/backend \
|
|
--logging-level "${LOGLEVEL:-INFO}" \
|
|
tasks.cron_config &
|
|
|
|
echo "Starting RQ worker..."
|
|
# Set PYTHONPATH so RQ can find the tasks module.
|
|
# Use a worker class that drops the noisy per-sweep "cleaning registries for
|
|
# queue" log line. The maintenance interval keeps its default (~10 min) so
|
|
# orphaned STARTED jobs and stale workers are still pruned promptly.
|
|
# --with-scheduler releases delayed jobs, which is how the watcher's rescans
|
|
# wait out their delay.
|
|
start_rq_worker() {
|
|
local name="$1"
|
|
shift
|
|
|
|
PYTHONPATH="/app/backend:${PYTHONPATH-}" \
|
|
RQ_REDIS_URL="${REDIS_URL}" \
|
|
rq worker \
|
|
--path /app/backend \
|
|
--worker-class handler.rq_worker.RomMWorker \
|
|
--pid "/tmp/${name}.pid" \
|
|
--logging_level "${LOGLEVEL:-INFO}" \
|
|
--with-scheduler \
|
|
"$@" &
|
|
}
|
|
|
|
start_rq_worker rq_worker high default low
|
|
|
|
# A scan runs for hours, so it gets its own worker: the queues above keep being
|
|
# served while it runs, and one worker on one queue keeps two scans from
|
|
# overlapping.
|
|
echo "Starting RQ scan worker..."
|
|
start_rq_worker rq_scan_worker scans
|
|
|
|
echo "Starting watcher..."
|
|
watchfiles \
|
|
--target-type command \
|
|
'uv run python watcher.py' \
|
|
/app/romm/library &
|
|
|
|
if [[ ${ENABLE_SYNC_FOLDER_WATCHER:-false} == "true" ]]; then
|
|
echo "Starting sync folder watcher..."
|
|
sync_base_path="${ROMM_BASE_PATH:-/romm}/sync"
|
|
mkdir -p "${sync_base_path}"
|
|
watchfiles \
|
|
--target-type command \
|
|
'uv run python sync_watcher.py' \
|
|
"${sync_base_path}" &
|
|
fi
|
|
|
|
# Start the frontend dev server
|
|
cd /app/frontend
|
|
npm run dev &
|
|
|
|
# Wait for all background processes
|
|
wait
|