Jellyfin: who is watching, and don't update a machine mid-film
New Jellyfin integration (read-only, every 2 minutes): version, restart wanted, streams and transcoding, failed scheduled tasks, item counts, failed sign-ins. Monitoring -> Jellyfin page with a peak-streams history, three alerts, /metrics. When Jellyfin runs on a managed server, an update run asks first if people are streaming (409 "watching" unless startAnyway), and a patch plan waits up to two hours for them before updating that server. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2f082ca5c2
commit
0146eb8bca
38 files changed
+8136
-13
No files matched your search
@@ -20,14 +20,15 @@ process.env.HEALTH_STARTUP_GRACE_MS = "0";
|
||||
|
||||
const express = (await import("express")).default;
|
||||
const { db } = await import("../src/db/client.js");
|
||||
const { users, servers, patchPlans, patchPlanRuns, updateRuns, maintenanceWindows } = await import("../src/db/schema.js");
|
||||
const { users, servers, patchPlans, patchPlanRuns, updateRuns, maintenanceWindows, integrations } = await import("../src/db/schema.js");
|
||||
const { runMigrations } = await import("../src/db/migrate.js");
|
||||
const { planServers, dueOccurrence, summariseItems, startPlanRun, advancePlanRuns, startDuePlans, cancelPlanRun, parseItems, PlanError } = await import("../src/services/patchPlans.js");
|
||||
const { advanceUpdateRuns, setSemaphoreForTests } = await import("../src/services/updateRuns.js");
|
||||
const { listActiveWindows } = await import("../src/services/maintenance.js");
|
||||
const { agendaFromData } = await import("../src/services/agenda.js");
|
||||
const { patchPlansRouter } = await import("../src/routes/patchPlans.js");
|
||||
const { updateSettings } = await import("../src/services/settingsStore.js");
|
||||
const { updateSettings, setInternalFlag } = await import("../src/services/settingsStore.js");
|
||||
const { storeRead } = await import("../src/services/jellyfinSync.js");
|
||||
const { eq } = await import("drizzle-orm");
|
||||
|
||||
await runMigrations();
|
||||
@@ -196,6 +197,39 @@ describe("a run, from start to end", () => {
|
||||
assert.match(last, /✓ web/);
|
||||
});
|
||||
|
||||
test("a server people are streaming from waits its turn for up to two hours, then is updated anyway", async () => {
|
||||
await reset({ tags: "[]", serverIds: JSON.stringify([ids.api]) });
|
||||
await db.update(servers).set({ ipAddresses: JSON.stringify(["10.7.7.7"]) }).where(eq(servers.id, ids.api));
|
||||
const jfId = (await db.insert(integrations).values({ type: "jellyfin", name: "Cinema", baseUrl: "http://10.7.7.7:8096", config: "{}" }).returning({ id: integrations.id }))[0].id;
|
||||
const seen = (m: number) => setInternalFlag("jellyfinSync", JSON.stringify({ [jfId]: { at: at(m).toISOString(), ok: true, error: null } }));
|
||||
try {
|
||||
await storeRead(jfId, { name: "Cinema", version: null, os: null, pendingRestart: false, updateAvailable: false, streams: [{ user: "Ann", client: null, device: null, title: "Dune", transcoding: false, paused: false }], tasks: [], counts: { movies: null, series: null, episodes: null, songs: null }, failedLogins24h: null }, T0);
|
||||
const run = await startPlanRun(planId, { trigger: "manual", actor: "Olle", now: T0 });
|
||||
|
||||
await seen(0);
|
||||
await advancePlanRuns(T0);
|
||||
let [item] = await itemsOf(run.id);
|
||||
assert.deepEqual([item.status, fake.runs.length], ["pending", 0], "somebody is watching, so it is not its turn yet");
|
||||
assert.match(item.message ?? "", /^Waiting: 1 person is streaming from Cinema \(Ann: Dune\)/);
|
||||
assert.equal(item.waitingSince, T0.toISOString());
|
||||
|
||||
await seen(60);
|
||||
await advancePlanRuns(at(60));
|
||||
[item] = await itemsOf(run.id);
|
||||
assert.deepEqual([item.status, fake.runs.length, item.waitingSince], ["pending", 0, T0.toISOString()], "an hour on, still waiting, and the wait is counted from the first time");
|
||||
|
||||
await seen(121);
|
||||
await advancePlanRuns(at(121));
|
||||
[item] = await itemsOf(run.id);
|
||||
assert.deepEqual([item.status, fake.runs.map((r) => r.limit)], ["running", ["api"]], "after two hours it goes ahead");
|
||||
assert.match(item.message ?? "", /^Went ahead after waiting 2 h; 1 person is streaming/);
|
||||
} finally {
|
||||
await db.delete(integrations).where(eq(integrations.id, jfId));
|
||||
await setInternalFlag("jellyfinSync", "{}");
|
||||
await db.update(servers).set({ ipAddresses: null }).where(eq(servers.id, ids.api));
|
||||
}
|
||||
});
|
||||
|
||||
test("what depends on a server is silenced while it is updated, and let go when it is done", async () => {
|
||||
await reset({ tags: "[]", serverIds: JSON.stringify([ids.web]) });
|
||||
const run = await startPlanRun(planId, { trigger: "manual", actor: "Olle", now: T0 });
|
||||
|
||||
Reference in new issue
Block a user