fix(server): archive.json on its own timer, a live Scheduled tab in one time zone, schedule audit in words
- SchedulerHost reads archive.json every 10 minutes on its own timer. The archive-scan runs that used to do it are skipped while a long scan is pending, and the schedule may be off or daily, so uploads kept a desktop's old folder template or proxy size. - Every schedule change and run, a skipped run included, is published as a scheduleChanged event. The Scheduled tab reloads on it, so skipped runs, next-run moves and other administrators' edits show without waiting for a job. - The Scheduled tab still draws when the schedule a job links to, or an expanded one, no longer exists: its runs are dropped instead of failing the whole load. - Every time on the Scheduled tab (next run, last result, runs) is in the server's time zone, as its "Times in" line says. - Audit details name a system schedule after its key (system:<key> · name · ...). The dashboard and the Logs page show it by its localized name and the recurrence code in words, as the Scheduled tab does. Older entries keep their recorded name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit c20f573d0bdf1cdcf3a86e9702ac76a4bf9508d9)
This commit is contained in:
1 parent
e384564784
commit
3f0e6357b1
10 files changed
+339
-43
No files matched your search
@@ -1,9 +1,12 @@
|
||||
// Audit entries as the dashboard and the Logs page show them: server codes (actions, job kinds, roles, changed
|
||||
// fields) in words; names, titles and templates stay as recorded.
|
||||
// fields, schedule recurrences) in words, system schedules by their names in the panel's language; other names, titles
|
||||
// and templates stay as recorded.
|
||||
import { t, has, plural } from "./i18n.js";
|
||||
import { formatBytes } from "./ui.js";
|
||||
import { kindLabel, pascal } from "./jobs.js";
|
||||
import { actionLabel as scheduleAction, outcomeLabel } from "./schedules.js";
|
||||
import { actionLabel as scheduleAction, outcomeLabel, scheduleName, recurrenceText, parseRecurrence } from "./schedules.js";
|
||||
|
||||
const SYSTEM = "system:";
|
||||
|
||||
export function actionLabel(action) {
|
||||
const key = `Admin.Logs.Action.${pascal(action)}`;
|
||||
@@ -37,16 +40,26 @@ export function detailText(entry) {
|
||||
case "sequence_updated":
|
||||
return details.split(", ").map(changeLabel).join(", ");
|
||||
case "schedule_run": {
|
||||
const [name, outcome] = splitLast(details);
|
||||
return outcome === undefined ? details : `${name} · ${outcomeLabel(outcome)}`;
|
||||
// "[system:<key> · ]name · outcome"
|
||||
const parts = details.split(" · ");
|
||||
if (parts.length < 2) return details;
|
||||
const outcome = parts.pop();
|
||||
return `${scheduleNameIn(parts)} · ${outcomeLabel(outcome)}`;
|
||||
}
|
||||
case "schedule_created":
|
||||
case "schedule_updated":
|
||||
case "schedule_deleted":
|
||||
case "schedule_reset": {
|
||||
// "name · action · recurrence[ · off]": the action in words, the name as typed (system schedules: as stored).
|
||||
const [name, action, ...rest] = details.split(" · ");
|
||||
return action === undefined ? details : [name, scheduleAction(action), ...rest.map((r) => r === "off" ? t("Admin.Schedules.Off") : r)].join(" · ");
|
||||
// "[system:<key> · ]name · action · recurrence[ · off]", read from the end: a name may hold the separator.
|
||||
const parts = details.split(" · ");
|
||||
const off = parts.at(-1) === "off";
|
||||
if (off) parts.pop();
|
||||
if (parts.length < 3) return details;
|
||||
const code = parts.pop();
|
||||
const action = parts.pop();
|
||||
const recurrence = parseRecurrence(code);
|
||||
const shown = [scheduleNameIn(parts), scheduleAction(action), recurrence ? recurrenceText(recurrence) : code];
|
||||
return (off ? [...shown, t("Admin.Schedules.Off")] : shown).join(" · ");
|
||||
}
|
||||
default:
|
||||
return details;
|
||||
@@ -66,6 +79,15 @@ function changeLabel(change) {
|
||||
return has(key) ? t(key) : change;
|
||||
}
|
||||
|
||||
/**
|
||||
* A schedule's name from the leading parts of audit details: after "system:<key>" a system schedule's in the panel's
|
||||
* language, as the Scheduled tab names it; else (a user's, or one recorded before keys were) as recorded.
|
||||
*/
|
||||
function scheduleNameIn(parts) {
|
||||
const systemKey = parts.length > 1 && parts[0].startsWith(SYSTEM) ? parts[0].slice(SYSTEM.length) : null;
|
||||
return scheduleName({ systemKey, name: (systemKey ? parts.slice(1) : parts).join(" · ") });
|
||||
}
|
||||
|
||||
function splitLast(details) {
|
||||
const at = details.lastIndexOf(" · ");
|
||||
return at < 0 ? [details] : [details.slice(0, at), details.slice(at + 3)];
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
// Scheduled jobs (owner review 2, R10): the Scheduled tab of the Jobs page (#/jobs?tab=schedules). Every schedule of the
|
||||
// server, its system schedules first (the timers it runs, shown so nothing runs out of sight), with when it runs in the
|
||||
// server's time zone, its next run, its last result and a switch; Run now, Edit, Delete (user schedules) and Reset
|
||||
// server, its system schedules first (the timers it runs, shown so nothing runs out of sight), with when it runs, its next
|
||||
// run, its last result (every time in the server's time zone) and a switch; Run now, Edit, Delete (user schedules) and Reset
|
||||
// (system schedules). A schedule's name opens its last runs, each linking to its job on the Queue tab. A side panel
|
||||
// creates and edits schedules: the action (those the server cannot run are disabled, their reason in the tooltip), the
|
||||
// recurrence, the action's parameters, priority, catch-up and the switch.
|
||||
import { t, plural, has, applyStrings, culture } from "./i18n.js";
|
||||
import { escapeHtml, attr, formatNumber, formatTime, formatDateTime, toast, errorText, confirmDialog, emptyState, redraw, focusPlace, restoreFocus, fitColumns,
|
||||
import { escapeHtml, attr, formatNumber, toast, errorText, confirmDialog, emptyState, redraw, focusPlace, restoreFocus, fitColumns,
|
||||
markInvalid, clearInvalid, invalidText } from "./ui.js";
|
||||
import { kindLabel, pascal, stateCell } from "./jobs.js";
|
||||
|
||||
const KINDS = ["every", "daily", "weekly", "monthly"];
|
||||
const UNITS = ["minutes", "hours", "days"];
|
||||
/** The unit letters of an interval's server code (every:10m). */
|
||||
const UNIT_CODES = { m: "minutes", h: "hours", d: "days" };
|
||||
/** Day names of the API, Monday first; 1 January 2001 was a Monday. */
|
||||
const DAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
||||
const PRIORITIES = ["background", "normal", "user"];
|
||||
@@ -68,6 +70,29 @@ export function recurrenceText(r) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The recurrence a server code describes (ScheduleRecurrence.Format: every:10m, daily:03:00, weekly:mon,thu@02:30,
|
||||
* monthly:1@04:00), in the API's shape for recurrenceText; null for anything else.
|
||||
*/
|
||||
export function parseRecurrence(code) {
|
||||
const match = /^(every|daily|weekly|monthly):(.+)$/.exec(String(code ?? ""));
|
||||
if (!match) return null;
|
||||
const [, kind, rest] = match;
|
||||
const isTime = (s) => /^\d{2}:\d{2}$/.test(s ?? "");
|
||||
if (kind === "every") {
|
||||
const every = /^(\d+)([mhd])$/.exec(rest);
|
||||
return every ? { kind, every: Number(every[1]), unit: UNIT_CODES[every[2]] } : null;
|
||||
}
|
||||
if (kind === "daily") return isTime(rest) ? { kind, time: rest } : null;
|
||||
const [what, time] = rest.split("@");
|
||||
if (!isTime(time)) return null;
|
||||
if (kind === "weekly") {
|
||||
const days = what.split(",");
|
||||
return days.every((d) => DAYS.includes(d)) ? { kind, days, time } : null;
|
||||
}
|
||||
return /^\d+$/.test(what) ? { kind, dayOfMonth: Number(what), time } : null;
|
||||
}
|
||||
|
||||
export async function renderSchedules(root, { api, setMeta, actions, onEvent }, focusSchedule) {
|
||||
let schedules = [];
|
||||
let available = [];
|
||||
@@ -116,11 +141,18 @@ export async function renderSchedules(root, { api, setMeta, actions, onEvent },
|
||||
steps = list.steps ?? [];
|
||||
zone = list.timeZone;
|
||||
locked = settings?.locked ?? [];
|
||||
// A schedule deleted meanwhile (here or by another administrator), or the one a job of the Queue tab links to after
|
||||
// its deletion, is simply not shown: its runs are not asked for.
|
||||
for (const id of expanded) {
|
||||
if (!find(id)) forget(id);
|
||||
}
|
||||
if (focusSchedule && !find(focusSchedule)) focusSchedule = null;
|
||||
// The state of each schedule's last job, for the Last result column (a job the history no longer has shows the outcome).
|
||||
const ids = [...new Set(schedules.filter((s) => s.lastJobId && s.lastOutcome === "queued").map((s) => s.lastJobId))];
|
||||
const jobs = await Promise.all(ids.map((id) => api.get(`/api/v1/jobs/${id}`).catch(() => null)));
|
||||
lastJobs = new Map(jobs.filter(Boolean).map((j) => [j.id, j]));
|
||||
await Promise.all([...expanded].map((id) => loadRuns(id)));
|
||||
// One schedule's runs that cannot be read (deleted since the list) close it; the table is drawn all the same.
|
||||
await Promise.all([...expanded].map((id) => loadRuns(id).catch(() => forget(id))));
|
||||
} catch (err) {
|
||||
toast(errorText(err), true);
|
||||
return;
|
||||
@@ -163,6 +195,12 @@ export async function renderSchedules(root, { api, setMeta, actions, onEvent },
|
||||
return schedules.find((s) => s.id === id);
|
||||
}
|
||||
|
||||
/** Closes a schedule's runs and drops them. */
|
||||
function forget(id) {
|
||||
expanded.delete(id);
|
||||
runs.delete(id);
|
||||
}
|
||||
|
||||
function rowHtml(s) {
|
||||
const name = scheduleName(s);
|
||||
const button = (act, key, extra = "") => `<button class="btn small${extra}" data-act="${act}" data-i18n="Admin.Schedules.${key}" data-i18n-title="Admin.Schedules.${key}.Tip"></button>`;
|
||||
@@ -187,8 +225,8 @@ export async function renderSchedules(root, { api, setMeta, actions, onEvent },
|
||||
/** The last result: the last job's state when the run queued one, else what the run did; when, in the tooltip's words. */
|
||||
function lastResult(s) {
|
||||
if (!s.lastRun) return `<span class="muted" data-i18n="Admin.Schedules.Never"></span>`;
|
||||
const when = `<span class="muted"> · ${escapeHtml(formatTime(s.lastRun))}</span>`;
|
||||
const tip = `${outcomeTip(s.lastOutcome)} · ${formatDateTime(s.lastRun)}`;
|
||||
const when = `<span class="muted"> · ${escapeHtml(zonedShort(s.lastRun, zone))}</span>`;
|
||||
const tip = `${outcomeTip(s.lastOutcome)} · ${zonedDateTime(s.lastRun, zone)}`;
|
||||
const job = s.lastOutcome === "queued" ? lastJobs.get(s.lastJobId) : null;
|
||||
if (job) return `<span title="${attr(tip)}">${stateCell(job.state)}${when}</span>`;
|
||||
const failed = String(s.lastOutcome).startsWith("failed:");
|
||||
@@ -203,7 +241,7 @@ export async function renderSchedules(root, { api, setMeta, actions, onEvent },
|
||||
}
|
||||
return `<div class="runs" role="list" aria-label="${attr(t("Admin.Schedules.RunsOf", scheduleName(s)))}">${page.items.map((j) => `
|
||||
<div class="run" role="listitem"><span class="ellipsis">${escapeHtml(kindLabel(j.kind))}</span><span>${stateCell(j.state)}</span>
|
||||
<span class="muted nowrap num">${escapeHtml(formatDateTime(j.created))}</span>
|
||||
<span class="muted nowrap num">${escapeHtml(zonedDateTime(j.created, zone))}</span>
|
||||
<a class="btn small" href="#/jobs?job=${attr(j.id)}" data-i18n="Admin.Schedules.OpenJob" data-i18n-title="Admin.Schedules.OpenJob.Tip"></a></div>`).join("")}
|
||||
${page.cursor ? `<button class="btn small more" data-more-runs="${attr(s.id)}" data-i18n="Admin.Common.More" data-i18n-title="Admin.Common.More.Tip"></button>` : ""}</div>`;
|
||||
}
|
||||
@@ -217,6 +255,7 @@ export async function renderSchedules(root, { api, setMeta, actions, onEvent },
|
||||
try {
|
||||
await loadRuns(id);
|
||||
} catch (err) {
|
||||
forget(id);
|
||||
toast(errorText(err), true);
|
||||
}
|
||||
draw();
|
||||
@@ -250,7 +289,7 @@ export async function renderSchedules(root, { api, setMeta, actions, onEvent },
|
||||
});
|
||||
if (!confirmed) return;
|
||||
await api.del(`/api/v1/schedules/${schedule.id}`);
|
||||
expanded.delete(schedule.id);
|
||||
forget(schedule.id);
|
||||
} else if (action === "reset") {
|
||||
const confirmed = await confirmDialog({
|
||||
title: t("Admin.Schedules.ResetTitle", scheduleName(schedule)),
|
||||
@@ -424,8 +463,9 @@ export async function renderSchedules(root, { api, setMeta, actions, onEvent },
|
||||
|
||||
setMeta("");
|
||||
onEvent((e) => {
|
||||
// A schedule's run queues jobs; their states change the Last result column.
|
||||
if (e.type === "jobState") {
|
||||
// A schedule changed or ran (also a run that queued nothing, or an edit by another administrator), or a job it queued
|
||||
// changed state (the Last result column); the burst of one pass is read once.
|
||||
if (e.type === "jobState" || e.type === "scheduleChanged") {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(load, 800);
|
||||
}
|
||||
@@ -498,17 +538,34 @@ function stepTip(step) {
|
||||
return has(key) ? t(key) : step;
|
||||
}
|
||||
|
||||
/** An instant in the server's time zone (schedule times are its wall-clock times); in the browser's when the zone is unknown here. */
|
||||
function zonedTime(iso, zone) {
|
||||
if (!iso) return "—";
|
||||
const options = { dateStyle: "short", timeStyle: "short" };
|
||||
/**
|
||||
* An instant in the server's time zone, as every time of this tab is ("Times in …": schedule times are its wall-clock
|
||||
* times); in the browser's when the zone is unknown here.
|
||||
*/
|
||||
function zoned(iso, zone, options) {
|
||||
const date = new Date(iso);
|
||||
try {
|
||||
return new Intl.DateTimeFormat(culture(), { ...options, timeZone: zone }).format(new Date(iso));
|
||||
return new Intl.DateTimeFormat(culture(), { ...options, timeZone: zone }).format(date);
|
||||
} catch {
|
||||
return new Intl.DateTimeFormat(culture(), options).format(new Date(iso));
|
||||
return new Intl.DateTimeFormat(culture(), options).format(date);
|
||||
}
|
||||
}
|
||||
|
||||
function zonedTime(iso, zone) {
|
||||
return iso ? zoned(iso, zone, { dateStyle: "short", timeStyle: "short" }) : "—";
|
||||
}
|
||||
|
||||
function zonedDateTime(iso, zone) {
|
||||
return iso ? zoned(iso, zone, { dateStyle: "short", timeStyle: "medium" }) : "—";
|
||||
}
|
||||
|
||||
/** Like formatTime in the server's time zone: the time when the instant falls on today there, else the date. */
|
||||
function zonedShort(iso, zone) {
|
||||
if (!iso) return "—";
|
||||
const day = (instant) => zoned(instant, zone, { dateStyle: "short" });
|
||||
return zoned(iso, zone, day(iso) === day(Date.now()) ? { timeStyle: "short" } : { dateStyle: "medium" });
|
||||
}
|
||||
|
||||
/** "03:00" as the panel's language writes a time of day. */
|
||||
function timeText(hhmm) {
|
||||
const [h, m] = String(hhmm ?? "").split(":").map(Number);
|
||||
|
||||
Reference in new issue
Block a user