fix(activity): a run nothing here has open reads as interrupted, a rollback sums a stopped run's spend

- The scheduler keeps one registry of the runs this process has open, for the interval jobs and the
  ad-hoc runs alike. A row the table still says is `running` but no run here has open (its outcome
  failed to write) reads as interrupted, as the next start's sweep will close it: no pulsing dot
  beside "No run recorded yet".
- Migration 0109's downgrade sums a still-running run's quota events into its spend before the link
  to them is dropped, as the startup sweep would.
- A test holds that a dialog closing onto the same address leaves an open log line open.
This commit is contained in:
2026-10-18 21:21:19 +02:00
parent 13b7577d9f
commit 5082636f15
5 changed files with 109 additions and 21 deletions
+11
View File
@@ -131,6 +131,13 @@ def test_a_down_and_up_round_trip_keeps_every_run(db, make_user):
),
{"u": uid},
)
# What the run caught mid-way had spent: only its quota rows know it yet.
conn.execute(
text(
"INSERT INTO quota_events (action, units, job_run_id)"
" SELECT 'videos.list', 7, id FROM job_runs WHERE job = 'maintenance'"
)
)
cfg = Config("alembic.ini")
command.downgrade(cfg, "0108_folder_links")
command.upgrade(cfg, "head")
@@ -141,6 +148,9 @@ def test_a_down_and_up_round_trip_keeps_every_run(db, make_user):
kept = conn.execute(
text("SELECT quota_units, finished_at - started_at FROM job_runs WHERE job = 'enrich'")
).one()
stopped = conn.execute(
text("SELECT quota_units FROM job_runs WHERE job = 'maintenance'")
).scalar()
stranded = conn.execute(
text("SELECT count(*) FROM audit_log WHERE action = 'job_run'")
).scalar()
@@ -151,4 +161,5 @@ def test_a_down_and_up_round_trip_keeps_every_run(db, make_user):
("enrich", "manual", None, None, "ok"),
]
assert tuple(kept) == (42, timedelta(minutes=30))
assert stopped == 7
assert stranded == 0