fix: reserve and persist background jobs

This commit is contained in:
Hermes Agent
2026-07-26 23:07:30 +00:00
parent 3b1bc9a2bf
commit 111b458ddf
4 changed files with 292 additions and 43 deletions
+31
View File
@@ -117,3 +117,34 @@ def test_expired_onchain_timestamp_triggers_real_refresh(server, monkeypatch, tm
assert saved["puell_multiple"]["source"] == "lookintobitcoin"
assert saved["sopr"]["source"] == "checkonchain"
assert saved["_onchain_timestamp"] != old.isoformat()
def test_refresh_job_is_reserved_before_thread_start(server, monkeypatch, tmp_path):
from dashboard.jobs import JobRegistry
registry = JobRegistry(tmp_path / "jobs.json")
monkeypatch.setattr(server, "_jobs", registry, raising=False)
monkeypatch.setattr(server, "_scraper_running", False)
started = server.api_refresh(full=False)
duplicate = server.api_refresh(full=False)
assert started["job_id"]
assert started["status"] == "queued"
assert registry.get(started["job_id"])["status"] == "queued"
assert duplicate.status_code == 409
def test_history_collection_has_job_id_and_job_scoped_progress(server, monkeypatch, tmp_path):
from dashboard.jobs import JobRegistry
registry = JobRegistry(tmp_path / "jobs.json")
monkeypatch.setattr(server, "_jobs", registry, raising=False)
started = server.api_backtest_collect()
job = registry.get(started["job_id"])
assert started["status"] == "queued"
assert job["kind"] == "history"
assert job["progress"] == {"status": "starting", "current": "", "step": 0, "total": 0}
assert server.api_job_status(started["job_id"])["id"] == started["job_id"]