Skip to content

Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring

fix: apply the status check interval to the running scheduler

JaG-v21343391b0dca
diff --git a/backend/app/api/routes/settings.py b/backend/app/api/routes/settings.py
index 7ec17bb..e0a63a5 100644
--- a/backend/app/api/routes/settings.py
+++ b/backend/app/api/routes/settings.py
@@ -4,13 +4,19 @@ from pydantic import BaseModel, Field
from app.api.deps import get_current_user
from app.core.config import settings
-from app.core.scheduler import reschedule_service_checks, set_service_checks_enabled
+from app.core.scheduler import (
+ reschedule_service_checks,
+ reschedule_status_checks,
+ set_service_checks_enabled,
+)
router = APIRouter()
class AppSettings(BaseModel):
- interval_seconds: int
+ # Mirrors the floor enforced by reschedule_status_checks(): rejecting here
+ # returns 422 instead of persisting the value and then failing with a 500.
+ interval_seconds: int = Field(ge=10)
service_check_enabled: bool = False
service_check_interval: int = Field(default=300, ge=30)
@@ -33,6 +39,10 @@ async def update_settings(
settings.service_check_enabled = payload.service_check_enabled
settings.service_check_interval = payload.service_check_interval
settings.save_overrides()
+ # Apply the status-check schedule live. Without this the new interval is
+ # persisted and shown in the UI, but the running job keeps the old one
+ # until the backend restarts.
+ reschedule_status_checks(payload.interval_seconds)
# Apply the service-check schedule live.
set_service_checks_enabled(payload.service_check_enabled)
if payload.service_check_enabled:
diff --git a/backend/tests/test_settings.py b/backend/tests/test_settings.py
index 8d1d7b0..670a589 100644
--- a/backend/tests/test_settings.py
+++ b/backend/tests/test_settings.py
@@ -37,6 +37,33 @@ async def test_update_settings_saves_interval(client: AsyncClient, headers):
assert res.json()["interval_seconds"] == 120
+async def test_update_settings_reschedules_status_checks(client: AsyncClient, headers):
+ """The new interval must reach the running scheduler, not just the config
+ file: otherwise the UI and scan_config.json show the new value while the
+ job keeps firing at the old one until the backend restarts."""
+ with patch("app.api.routes.settings.settings") as mock_settings, \
+ patch("app.api.routes.settings.reschedule_status_checks") as mock_reschedule:
+ mock_settings.save_overrides = lambda: None
+ res = await client.post(
+ "/api/v1/settings",
+ json={"interval_seconds": 120},
+ headers=headers,
+ )
+ assert res.status_code == 200
+ mock_reschedule.assert_called_once_with(120)
+
+
+async def test_update_settings_rejects_too_short_status_interval(client: AsyncClient, headers):
+ res = await client.post(
+ "/api/v1/settings",
+ json={"interval_seconds": 5},
+ headers=headers,
+ )
+ assert res.status_code == 422
+
+
@pytest.mark.asyncio
async def test_update_settings_requires_auth(client: AsyncClient):
res = await client.post("/api/v1/settings", json={"interval_seconds": 30})