fix: reserve and persist background jobs
This commit is contained in:
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user