mirror of
https://github.com/rommapp/romm.git
synced 2026-12-03 10:33:22 +01:00
Scheduling moved onto RQ, which left the task catalog with two identity schemes: the registry key a job payload now carries, and the dotted func path each PeriodicTask still declared. Nothing read the latter, so it is gone, along with the test that guarded paths no payload names. Four sites built the same enqueue by hand and had already drifted: the startup backfills passed the global timeout and no result_ttl, so an auto-enqueued conversion fell out of the task list after RQ's default 500s while the same task triggered by an admin lived for TASK_RESULT_TTL. They now go through enqueue_task, which derives timeout, ttl and meta from the task itself. Scan discovery paid a Redis round trip per queued job to re-read a status the fetch already carried, and the stale sweep read every delayed job to find the few past due. Both now ask Redis once. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
39 lines
1.2 KiB
Python
39 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 two 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",
|
|
)
|
|
|
|
|
|
@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}"
|