refactor(config): fold maintenance_revalidate_batch from app_state into sysconfig (E3 S3, B-core-11)

The admin-tunable maintenance re-validation batch lived in its own app_state
column with a hand-rolled override-or-default reader in app.state — a fourth
config store duplicating the sysconfig SPECS pattern. Move it to a sysconfig key
(`maintenance` group, min=100 max=100_000): the reader (sync/maintenance.py) and
the Scheduler dashboard (routes/scheduler.py PATCH + GET) now go through
sysconfig.get_int / set_value / spec, and app.state loses get/set_maintenance_batch
+ the MIN/MAX constants + the settings import. Migration 0070 carries any existing
override into the system_config store before dropping the app_state column
(reversible; restores + copies back on downgrade). Reuses the existing
sysconfig.spec() for the dashboard's min/max, so the bounds have one source.

Full lane 365 pass (migration drift + reversibility exercised), ruff clean.
This commit is contained in:
2026-08-18 23:40:45 +02:00
parent d37b6ef07f
commit 8a97c79d37
6 changed files with 61 additions and 38 deletions
+8 -10
View File
@@ -91,16 +91,14 @@ def set_maintenance_settings(
) -> dict:
"""Admin-tune the maintenance job's rolling re-validation batch (videos re-checked per
run). Persisted to app_state; the job reads it each run."""
value = body.revalidate_batch
if not (state.MAINTENANCE_BATCH_MIN <= value <= state.MAINTENANCE_BATCH_MAX):
s = sysconfig.spec("maintenance_revalidate_batch")
if not (s.min <= body.revalidate_batch <= s.max):
raise HTTPException(
status_code=400,
detail=(
f"revalidate_batch must be between {state.MAINTENANCE_BATCH_MIN} and "
f"{state.MAINTENANCE_BATCH_MAX}"
),
detail=f"revalidate_batch must be between {s.min} and {s.max}",
)
new = state.set_maintenance_batch(db, value)
sysconfig.set_value(db, "maintenance_revalidate_batch", body.revalidate_batch)
new = sysconfig.get_int(db, "maintenance_revalidate_batch")
audit.record(db, admin.id, AuditAction.MAINTENANCE_TUNE, summary=f"revalidate batch = {new}", after={"revalidate_batch": new})
db.commit()
return {"revalidate_batch": new}
@@ -174,9 +172,9 @@ def get_scheduler(
"queue": queue,
"quota": quota_info,
"maintenance": {
"revalidate_batch": state.get_maintenance_batch(db),
"revalidate_batch": sysconfig.get_int(db, "maintenance_revalidate_batch"),
"revalidate_batch_default": settings.maintenance_revalidate_batch,
"min": state.MAINTENANCE_BATCH_MIN,
"max": state.MAINTENANCE_BATCH_MAX,
"min": sysconfig.spec("maintenance_revalidate_batch").min,
"max": sysconfig.spec("maintenance_revalidate_batch").max,
},
}