Fragnet: reads checked against a live account; interval and one-off schedules
Inspect on a real Fragnet panel showed every read answers as the reader expects. Schedules that run every so often or once (interval_value, interval_unit, run_at) carry no cron fields, so they were shown as a cron of stars; they now read "every 6 hours" or "once, ...", and the page hides an empty label. Test and INTEGRATIONS.md updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
01fb5d6335
commit
a91efcbfe2
4 files changed
+31
-5
No files matched your search
@@ -241,6 +241,23 @@ export function parseNewBackup(raw: unknown): FragnetBackup | null {
|
||||
return parseBackups({ data: [raw] })[0] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* When a schedule runs, as one line. Most carry a cron (the five fields, joined); the panel also has schedules that run every so often (`has_interval`, `interval_value`, `interval_unit`) or
|
||||
* once (`run_at`), whose cron object says nothing — those read "every 6 hours" or "once, 2026-06-02 04:00", rather than a cron of stars that would claim "every minute".
|
||||
*/
|
||||
function whenItRuns(s: Record<string, unknown>): string {
|
||||
const c = obj(s.cron);
|
||||
const fields = [c.minute, c.hour, c.day_of_month, c.month, c.day_of_week];
|
||||
const given = (x: unknown) => (typeof x === "string" && x.trim() !== "") || typeof x === "number";
|
||||
if (fields.some(given)) return fields.map((x) => (given(x) ? String(x) : "*")).join(" ");
|
||||
const every = num(s.interval_value);
|
||||
const unit = str(s.interval_unit);
|
||||
if (s.has_interval === true && every !== null && every > 0 && unit) return `every ${every === 1 ? "" : `${every} `}${unit.replace(/s$/i, "")}${every === 1 ? "" : "s"}`;
|
||||
const once = iso(s.run_at);
|
||||
if (once) return `once, ${once.slice(0, 16).replace("T", " ")}`;
|
||||
return "";
|
||||
}
|
||||
|
||||
/** Pure: `…/schedules` — the tasks that run on their own (a restart every night, a backup every Sunday). */
|
||||
export function parseSchedules(raw: unknown): FragnetSchedule[] {
|
||||
const out: FragnetSchedule[] = [];
|
||||
@@ -249,9 +266,7 @@ export function parseSchedules(raw: unknown): FragnetSchedule[] {
|
||||
const id = num(s.id);
|
||||
const name = str(s.name);
|
||||
if (id === null || !name) continue;
|
||||
const c = obj(s.cron);
|
||||
const cron = [c.minute, c.hour, c.day_of_month, c.month, c.day_of_week].map((x) => (typeof x === "string" || typeof x === "number" ? String(x) : "*")).join(" ");
|
||||
out.push({ id, name, cron, active: s.is_active !== false, processing: s.is_processing === true, onlyWhenOnline: s.only_when_online === true, lastRunAt: iso(s.last_run_at), nextRunAt: iso(s.next_run_at) });
|
||||
out.push({ id, name, cron: whenItRuns(s), active: s.is_active !== false, processing: s.is_processing === true, onlyWhenOnline: s.only_when_online === true, lastRunAt: iso(s.last_run_at), nextRunAt: iso(s.next_run_at) });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -136,6 +136,17 @@ describe("what the panel's API says", () => {
|
||||
assert.deepEqual([s.id, s.name, s.cron, s.active, s.onlyWhenOnline, s.nextRunAt], [4, "Nightly restart", "0 4 * * *", true, true, "2026-06-02T04:00:00.000Z"]);
|
||||
});
|
||||
|
||||
test("a schedule that runs every so often or once is not shown as a cron of stars", () => {
|
||||
const run = (attributes: Record<string, unknown>) => adapter.parseSchedules({ data: [{ attributes: { id: 1, name: "x", ...attributes } }] })[0].cron;
|
||||
const none = { minute: "", hour: "", day_of_month: "", month: "", day_of_week: "" };
|
||||
assert.equal(run({ cron: none, has_interval: true, interval_value: 6, interval_unit: "hours", run_at: "2026-06-02T04:00:00+00:00" }), "every 6 hours");
|
||||
assert.equal(run({ cron: {}, has_interval: true, interval_value: 1, interval_unit: "hour" }), "every hour");
|
||||
assert.equal(run({ cron: none, has_interval: false, run_at: "2026-06-02T04:00:00+00:00" }), "once, 2026-06-02 04:00");
|
||||
assert.equal(run({ cron: none }), "", "nothing known says nothing");
|
||||
assert.equal(run({ cron: { minute: "*/5", hour: "*", day_of_month: "*", month: "*", day_of_week: "*" } }), "*/5 * * * *");
|
||||
assert.equal(run({ cron: { minute: "0", hour: "4" } }), "0 4 * * *", "a cron with fields left out keeps its stars");
|
||||
});
|
||||
|
||||
test("the next page is the one after this, up to the last", () => {
|
||||
assert.equal(adapter.nextPage({ meta: { pagination: { current_page: 1, total_pages: 2 } } }), 2);
|
||||
assert.equal(adapter.nextPage({ meta: { pagination: { current_page: 2, total_pages: 2 } } }), null);
|
||||
|
||||
Reference in new issue
Block a user