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:
Alby96 committed 2026-10-27 09:57:23 +01:00
1 parent e384564784
commit 3f0e6357b1
10 files changed
+339 -43

No files matched your search

+73 -16
View File
@@ -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);