diff --git a/INTEGRATIONS.md b/INTEGRATIONS.md index 0f3422c..3b1a0c9 100644 --- a/INTEGRATIONS.md +++ b/INTEGRATIONS.md @@ -558,7 +558,7 @@ osTicket's API cannot close a ticket, so this is the one place in the app that * whose failure is more than a week old, is not raised. - If n8n cannot be read for 20 minutes its alerts are neither raised nor cleared, and the Alerts page says it could not check. If the runs could not be read (but the workflows could), the last outcomes are *unknown* and nothing is claimed. - `/metrics` has `homelab_n8n_workflows`, `homelab_n8n_workflows_active` and `homelab_n8n_workflows_failing` for each n8n that was read lately. -- **Not verified against a live n8n** — the endpoints and fields are as n8n documents them and the reader is tried against a pretend server that pages with a cursor. A workflow that runs less often than 250 other runs go by may show no run (and so no alert); the page says it is judged from the newest 250. +- **Checked against a live n8n** (Inspect: the workflow list and the run list both answered as the reader expects, with nothing empty). **Archived workflows** (`isArchived`) are left out. It is also tried against a pretend server that pages with a cursor. A workflow that runs less often than 250 other runs go by may show no run (and so no alert); the page says it is judged from the newest 250. ### Paperless-ngx diff --git a/server/src/integrations/n8n/adapter.ts b/server/src/integrations/n8n/adapter.ts index 1fce6bd..4456732 100644 --- a/server/src/integrations/n8n/adapter.ts +++ b/server/src/integrations/n8n/adapter.ts @@ -4,8 +4,8 @@ * Reading only: the workflows (and which are switched on), and the most recent runs, from which each workflow's **last run** and how many runs failed in the last day are worked out — * an automation that has been failing since Tuesday is what is worth hearing about. Nothing is sent to n8n but GET requests for these. * - * Endpoints and field names are from n8n's published public API (`/api/v1/workflows`, `/api/v1/executions`) and have not been checked against a live server here; every field is - * read defensively. Only the newest 250 runs are looked at, so a workflow that runs more rarely than that many other runs may show no run. + * Endpoints and field names are from n8n's published public API (`/api/v1/workflows`, `/api/v1/executions`) and were checked against a live server (Inspect: every field the reader + * uses had a value); every field is still read defensively. Only the newest 250 runs are looked at, so a workflow that runs more rarely than that many other runs may show no run. */ import { requestJson } from "../httpJson.js"; import { withDiagLogging } from "../../services/diagLog.js"; @@ -48,13 +48,14 @@ const iso = (v: unknown): string | null => { export const FAILED_STATUSES = new Set(["error", "crashed"]); const PAGES = 4; -/** Pure: the workflows of one page. */ +/** Pure: the workflows of one page, archived ones left out. */ export function parseWorkflows(raw: unknown): { id: string; name: string; active: boolean }[] { const out: { id: string; name: string; active: boolean }[] = []; for (const item of Array.isArray(obj(raw).data) ? (obj(raw).data as unknown[]) : []) { const w = obj(item); const id = str(w.id); - if (!id) continue; + // An archived workflow is out of the way in n8n (and never active): it isn't one to list or count. + if (!id || w.isArchived === true) continue; out.push({ id, name: str(w.name) ?? id, active: w.active === true }); } return out; diff --git a/server/test/n8n.test.ts b/server/test/n8n.test.ts index 98811e6..4b52ed2 100644 --- a/server/test/n8n.test.ts +++ b/server/test/n8n.test.ts @@ -51,6 +51,11 @@ describe("what n8n's API says", () => { assert.deepEqual(adapter.parseWorkflows(null), []); }); + test("an archived workflow (n8n marks it isArchived) is left out", () => { + const w = adapter.parseWorkflows({ data: [{ id: "a", name: "Live", active: true, isArchived: false }, { id: "b", name: "Put away", active: false, isArchived: true }] }); + assert.deepEqual(w, [{ id: "a", name: "Live", active: true }]); + }); + test("each workflow's last outcome is the newest finished run; a run still going is not an outcome; failures are counted for the last day", () => { const workflows = [{ id: "1", name: "A", active: true }, { id: "2", name: "B", active: true }, { id: "3", name: "C", active: false }]; const runs = {