feat(subs): kick off the first backfill walk immediately on source create
CI / lint (push) Successful in 3s
CI / frontend-build (push) Successful in 24s
CI / backend-lint-and-test (push) Successful in 26s
CI / integration (push) Successful in 3m3s

A new enabled source is armed for run-until-done backfill (#693) but would sit
idle until the next scheduler tick (~60s). create_source now enqueues the first
walk right away (pending DownloadEvent + download_source.delay), skipping only
when the platform is in a rate-limit cooldown (the scheduler picks it up when
that clears). Disabled sources still don't dispatch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-06 21:22:32 -04:00
parent 87c7318125
commit a3c9499e93
2 changed files with 49 additions and 0 deletions
+33
View File
@@ -89,6 +89,39 @@ async def test_create_list_get_delete(client, artist):
assert (await client.get(f"/api/sources/{sid}")).status_code == 404
@pytest.mark.asyncio
async def test_create_kicks_off_backfill_for_enabled_source(client, artist, monkeypatch):
"""A new enabled source dispatches its first walk immediately (no waiting
for the next scheduler tick), unless its platform is in cooldown."""
delays: list = []
monkeypatch.setattr(
"backend.app.tasks.download.download_source.delay",
lambda *a, **k: delays.append(a),
)
resp = await client.post("/api/sources", json={
"artist_id": artist.id, "platform": "patreon",
"url": "https://patreon.com/kickoff",
})
assert resp.status_code == 201
sid = (await resp.get_json())["id"]
assert delays == [(sid,)]
@pytest.mark.asyncio
async def test_create_disabled_source_does_not_kick_off(client, artist, monkeypatch):
delays: list = []
monkeypatch.setattr(
"backend.app.tasks.download.download_source.delay",
lambda *a, **k: delays.append(a),
)
resp = await client.post("/api/sources", json={
"artist_id": artist.id, "platform": "patreon",
"url": "https://patreon.com/disabled", "enabled": False,
})
assert resp.status_code == 201
assert delays == []
@pytest.mark.asyncio
async def test_create_rejects_unknown_platform(client, artist):
resp = await client.post("/api/sources", json={