mirror of
https://github.com/rommapp/romm.git
synced 2026-12-06 07:54:18 +01:00
The registry imported every task module to read each task's title, schedule, queue and timeout, so `rq cron` and every RQ worker parent loaded the whole app. Task metadata now lives in the registry as `TaskSpec`s with a dotted path to the implementation, which `get_task` imports only when a job runs. Cron, the tasks API, enqueueing and the worker's failure reporting read specs only. Every log line also imported handler.metadata.base_handler, and with it every metadata provider, for the redaction regex. The sensitive keys and their regex now live in logger.formatter. A test pins that importing the cron config or the worker class loads neither handler.database, the auth handlers nor fastapi. Measured RSS at LOGLEVEL=INFO, master -> this branch: - rq cron: 164 MB -> 72 MB - idle RQ worker (x3): 133 MB -> 68 MB - gunicorn web worker: 214 MB -> 206 MB Each job's work horse now imports its task module itself, 0.1-0.5s more per job on an x86 host. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gh1SRMfuK7BZmf6YxMqSyT
26 lines
1022 B
Python
26 lines
1022 B
Python
from dataclasses import replace
|
|
|
|
from handler.database import db_sync_session_handler
|
|
from tasks.registry import CLEANUP_SYNC_SESSIONS_SPEC
|
|
from tasks.scheduled.cleanup_sync_sessions import CleanupSyncSessionsTask
|
|
|
|
|
|
class TestCleanupSyncSessionsTask:
|
|
def test_default_schedule(self):
|
|
assert CLEANUP_SYNC_SESSIONS_SPEC.enabled is True
|
|
assert CLEANUP_SYNC_SESSIONS_SPEC.cron_string == "23 * * * *"
|
|
|
|
async def test_disabled_cleanup_leaves_sessions_open(self, mocker):
|
|
fail_stale = mocker.patch.object(db_sync_session_handler, "fail_stale_sessions")
|
|
task = CleanupSyncSessionsTask()
|
|
task.spec = replace(task.spec, enabled=False)
|
|
await task.run()
|
|
fail_stale.assert_not_called()
|
|
|
|
async def test_enabled_cleanup_fails_stale_sessions(self, mocker):
|
|
fail_stale = mocker.patch.object(
|
|
db_sync_session_handler, "fail_stale_sessions", return_value=2
|
|
)
|
|
await CleanupSyncSessionsTask().run()
|
|
fail_stale.assert_called_once()
|