Commit 6425eab
Live channels: background scheduler + authoring/control UI (slices 3-4)
Completes the live-channel feature on top of the engine primitives from the prior
commits: a background scheduler that auto-updates channels marked "live", and the
UI to author and control it. Ships OFF (recipes_enabled defaults false).
Backend — scheduler (backend/scheduler.py, new):
- A single in-process asyncio loop started from main.py's lifespan. Wakes every
60s and runs a cycle when recipes_enabled is true, not paused, and
recipe_interval_hours has elapsed (re-reads config each tick, so toggles apply
within a minute — mirrors how the auth middleware re-reads config per request).
- Each cycle (under deploy_lock, blocking I/O offloaded to a worker thread):
build the Tunarr index once, then for every "live": true channel, re-resolve
its content and diff the fresh program-id set against read_channel_programming
(the channel's currently-scheduled set). Patch in place via
update_channel_in_place ONLY on a difference. No state file — Tunarr is the
source of truth, so the loop survives restarts and an unchanged channel is a
cheap no-op (no Plex guide churn). 404 / unreadable / resolves-to-empty are
skipped and logged, never fatal.
- Writes a rolling diff log to data/logs/recipes.log; keeps last_cycle in memory.
- deploy_lock (asyncio.Lock) is shared with pipeline_router: probe/deploy/
deploy-selective now stream through _locked_stream, so a manual deploy and a
scheduler cycle never touch Tunarr concurrently.
Backend — endpoints (recipes_router.py):
- GET /api/recipes/status — enabled, paused, running, interval, live_count, last_cycle
- POST /api/recipes/run?apply= — run one cycle on demand; apply=false is a dry run
(detect + log, no Tunarr writes). Same code path the loop uses — the test/refresh trigger.
- POST /api/recipes/pause?paused= — runtime kill switch, no restart needed.
- POST /api/recipes/config — merge-writes recipes_enabled / recipe_interval_hours
into config.json. Deliberately separate from the strict /config ConfigModel,
which rewrites the whole file and would drop unknown keys.
Frontend (slice 4):
- Channels page: the edit modal gains a "Live recipe" section — a Switch to mark
the channel live, and a franchise auto-match builder. The builder calls
/api/recipes/preview and shows matched titles as a checklist; unchecking a title
adds it to the rule's exclude (the false-positive escape hatch). Saving stores a
{"match":"title_contains", value, order, exclude} entry in the channel's content.
A "live" badge marks live channels.
- Settings: a "Live Channels" card — master enable Switch + check-interval input,
saved via /api/recipes/config.
- Dashboard: an "Auto-Updates" card (shown when enabled or any channel is live) —
on/paused state, live count + interval, last-cycle changes, Pause/Resume toggle,
and a "Check now" button.
Verified locally in Docker against live Plex/Tunarr (no mutations):
- Scheduler: idempotent no-op cycle = changed:0; positive detection (synthetic
live channel) correctly reports adds with human labels (e.g. "Martin x132");
dry-run mutates nothing; loop auto-runs on boot when enabled, idle when disabled.
- UI/endpoints: SPA serves; POST /api/recipes/config persists enabled+interval and
leaves all connection/auth keys intact (clobber check); status reflects changes;
frontend builds clean (tsc + vite).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 2237bd6 commit 6425eab
8 files changed
Lines changed: 804 additions & 35 deletions
File tree
- backend
- routers
- frontend/src
- api
- pages
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
32 | 42 | | |
33 | 43 | | |
34 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
91 | 93 | | |
92 | 94 | | |
93 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
94 | 107 | | |
95 | 108 | | |
96 | 109 | | |
| |||
272 | 285 | | |
273 | 286 | | |
274 | 287 | | |
275 | | - | |
| 288 | + | |
276 | 289 | | |
277 | 290 | | |
278 | 291 | | |
| |||
284 | 297 | | |
285 | 298 | | |
286 | 299 | | |
287 | | - | |
| 300 | + | |
288 | 301 | | |
289 | 302 | | |
290 | 303 | | |
| |||
319 | 332 | | |
320 | 333 | | |
321 | 334 | | |
322 | | - | |
| 335 | + | |
323 | 336 | | |
324 | 337 | | |
325 | 338 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
0 commit comments