mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +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>
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
import os
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
BACKEND_ROOT = Path(__file__).resolve().parents[2]
|
|
|
|
# The only callables a job payload names. Everything else runs through
|
|
# run_task_by_name, which resolves it from the registry.
|
|
JOB_FUNC_PATHS = (
|
|
"tasks.tasks.run_task_by_name",
|
|
"endpoints.sockets.scan.scan_platforms",
|
|
"tasks.registry.enqueue_scheduled_scan",
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("func", JOB_FUNC_PATHS)
|
|
def test_task_func_resolves_in_a_fresh_interpreter(func):
|
|
"""The RQ worker resolves a job by importing its func path into a process
|
|
where that module is the first application module imported. An import cycle
|
|
that stays hidden in the web process breaks the job there."""
|
|
result = subprocess.run(
|
|
[
|
|
sys.executable,
|
|
"-c",
|
|
"import sys\n"
|
|
"from rq.utils import import_attribute\n"
|
|
"assert callable(import_attribute(sys.argv[1]))\n",
|
|
func,
|
|
],
|
|
cwd=BACKEND_ROOT,
|
|
env={**os.environ, "PYTHONPATH": str(BACKEND_ROOT)},
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
|
|
assert result.returncode == 0, f"{func} is not importable by RQ:\n{result.stderr}"
|