swarm ui: a fire now button on each schedule
This commit is contained in:
parent
0db9868eee
commit
db924d9e77
6 changed files with 62 additions and 3 deletions
|
|
@ -10,6 +10,11 @@ Operators manage them with `swarmctl schedule` on the swarm controller's
|
||||||
host. Agents can't create, change or remove one. For a one-off wake an agent
|
host. Agents can't create, change or remove one. For a one-off wake an agent
|
||||||
sets itself, it uses `remind`, which stays inside its container.
|
sets itself, it uses `remind`, which stays inside its container.
|
||||||
|
|
||||||
|
The schedules card on the swarm UI's messages tab does the same, and adds **fire
|
||||||
|
now**, which fires a prompt at once by moving its start to this moment. A
|
||||||
|
repeating prompt then carries on from now, at its interval, not at its old clock
|
||||||
|
times. A paused prompt has no fire now; resume it first.
|
||||||
|
|
||||||
## Managing them
|
## Managing them
|
||||||
|
|
||||||
```console
|
```console
|
||||||
|
|
|
||||||
|
|
@ -352,7 +352,10 @@ The **schedules** card on the **messages** tab holds one card per scheduled
|
||||||
prompt. It starts shut and reads nothing until you open it; the old `/schedules` address
|
prompt. It starts shut and reads nothing until you open it; the old `/schedules` address
|
||||||
redirects to the messages tab. The **name** is the card's
|
redirects to the messages tab. The **name** is the card's
|
||||||
title, with the **agents** it fires for, the message, how often it repeats and
|
title, with the **agents** it fires for, the message, how often it repeats and
|
||||||
when it fires next. **edit** turns the card into its own form; **pause** and
|
when it fires next. **edit** turns the card into its own form; **fire now** sends
|
||||||
|
`PATCH /api/schedules/{id}` with the current second as `anchor_unix`, so a start
|
||||||
|
that has passed fires its latest time right away and a repeating schedule goes on
|
||||||
|
from there at its interval (a paused schedule has no fire now); **pause** and
|
||||||
**resume** stop and restart it; **remove** deletes it after a confirmation.
|
**resume** stop and restart it; **remove** deletes it after a confirmation.
|
||||||
**+ schedule** opens an empty form above the list, and the filters narrow the
|
**+ schedule** opens an empty form above the list, and the filters narrow the
|
||||||
list by name, agent or state (`active`, `paused`, or `past` for a one-shot
|
list by name, agent or state (`active`, `paused`, or `past` for a one-shot
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// <ScheduleCard> — one scheduled prompt as a card: its name as the title,
|
// <ScheduleCard> — one scheduled prompt as a card: its name as the title,
|
||||||
// "agents: foo, bar" beneath, then the message, the cadence and when it
|
// "agents: foo, bar" beneath, then the message, the cadence and when it
|
||||||
// fires next. Edit, pause/resume and remove sit at the foot; edit swaps the
|
// fires next. Edit, fire now, pause/resume and remove sit at the foot; edit swaps the
|
||||||
// card for `ScheduleForm` (the page owns that swap).
|
// card for `ScheduleForm` (the page owns that swap).
|
||||||
import { Badge, type BadgeTone } from "@hive/shared/badge.js";
|
import { Badge, type BadgeTone } from "@hive/shared/badge.js";
|
||||||
import { ActionRow } from "../../ui/action-row/ActionRow.js";
|
import { ActionRow } from "../../ui/action-row/ActionRow.js";
|
||||||
|
|
@ -27,6 +27,7 @@ export function ScheduleCard({
|
||||||
schedule,
|
schedule,
|
||||||
pending,
|
pending,
|
||||||
onEdit,
|
onEdit,
|
||||||
|
onFireNow,
|
||||||
onTogglePaused,
|
onTogglePaused,
|
||||||
onRemove,
|
onRemove,
|
||||||
}: {
|
}: {
|
||||||
|
|
@ -34,6 +35,7 @@ export function ScheduleCard({
|
||||||
/** A pause/resume or remove for this schedule is in flight. */
|
/** A pause/resume or remove for this schedule is in flight. */
|
||||||
pending: boolean;
|
pending: boolean;
|
||||||
onEdit: () => void;
|
onEdit: () => void;
|
||||||
|
onFireNow: () => void;
|
||||||
onTogglePaused: () => void;
|
onTogglePaused: () => void;
|
||||||
onRemove: () => void;
|
onRemove: () => void;
|
||||||
}) {
|
}) {
|
||||||
|
|
@ -78,6 +80,19 @@ export function ScheduleCard({
|
||||||
<Button onClick={onEdit} disabled={pending}>
|
<Button onClick={onEdit} disabled={pending}>
|
||||||
edit
|
edit
|
||||||
</Button>
|
</Button>
|
||||||
|
<span
|
||||||
|
title={
|
||||||
|
schedule.paused
|
||||||
|
? "resume it first: a paused schedule does not fire"
|
||||||
|
: schedule.interval_seconds === null
|
||||||
|
? "fires it now: its start moves to this moment"
|
||||||
|
: "fires it now: its start moves to this moment, so it repeats from now on"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Button onClick={onFireNow} disabled={pending || schedule.paused}>
|
||||||
|
fire now
|
||||||
|
</Button>
|
||||||
|
</span>
|
||||||
<Button onClick={onTogglePaused} disabled={pending}>
|
<Button onClick={onTogglePaused} disabled={pending}>
|
||||||
{schedule.paused ? "resume" : "pause"}
|
{schedule.paused ? "resume" : "pause"}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
@ -115,6 +130,7 @@ function ScheduleCardSkeleton() {
|
||||||
</div>
|
</div>
|
||||||
<ActionRow align="end" class="ui-schedule-card-actions">
|
<ActionRow align="end" class="ui-schedule-card-actions">
|
||||||
<Skeleton width="4em" height="2.75em" />
|
<Skeleton width="4em" height="2.75em" />
|
||||||
|
<Skeleton width="5.5em" height="2.75em" />
|
||||||
<Skeleton width="4.5em" height="2.75em" />
|
<Skeleton width="4.5em" height="2.75em" />
|
||||||
<Skeleton width="5em" height="2.75em" />
|
<Skeleton width="5em" height="2.75em" />
|
||||||
</ActionRow>
|
</ActionRow>
|
||||||
|
|
|
||||||
|
|
@ -101,3 +101,13 @@ export function fmtLocal(unix: number): string {
|
||||||
timeStyle: "short",
|
timeStyle: "short",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `PATCH /api/schedules/{id}` body that fires a schedule now: its start
|
||||||
|
* (the origin of its fire times) moves to `nowMs`, and a start that has passed
|
||||||
|
* fires its latest time right away. A repeating schedule goes on from there, so
|
||||||
|
* its later fires keep the interval but not their old clock times.
|
||||||
|
*/
|
||||||
|
export function fireNowBody(nowMs: number): { anchor_unix: number } {
|
||||||
|
return { anchor_unix: Math.floor(nowMs / 1000) };
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import type { AgentRow } from "../../agent/AgentTypes.js";
|
||||||
import { ScheduleCard, ScheduleListSkeleton } from "./ScheduleCard.js";
|
import { ScheduleCard, ScheduleListSkeleton } from "./ScheduleCard.js";
|
||||||
import { agentNamesFrom, agentOptionsFor } from "./agent-options.js";
|
import { agentNamesFrom, agentOptionsFor } from "./agent-options.js";
|
||||||
import { ScheduleForm } from "./ScheduleForm.js";
|
import { ScheduleForm } from "./ScheduleForm.js";
|
||||||
import { scheduleState, type Schedule } from "./ScheduleTypes.js";
|
import { fireNowBody, scheduleState, type Schedule } from "./ScheduleTypes.js";
|
||||||
|
|
||||||
// A refetch never touches an open form's own state (it lives in the form),
|
// A refetch never touches an open form's own state (it lives in the form),
|
||||||
// so the usual 30s default is safe here too.
|
// so the usual 30s default is safe here too.
|
||||||
|
|
@ -118,6 +118,16 @@ function SchedulesBody() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fireNow(s: Schedule) {
|
||||||
|
return act(s.id, () =>
|
||||||
|
fetch(`/api/schedules/${encodeURIComponent(s.id)}`, {
|
||||||
|
method: "PATCH",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify(fireNowBody(Date.now())),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function togglePaused(s: Schedule) {
|
function togglePaused(s: Schedule) {
|
||||||
return act(s.id, () =>
|
return act(s.id, () =>
|
||||||
fetch(`/api/schedules/${encodeURIComponent(s.id)}`, {
|
fetch(`/api/schedules/${encodeURIComponent(s.id)}`, {
|
||||||
|
|
@ -207,6 +217,7 @@ function SchedulesBody() {
|
||||||
schedule={s}
|
schedule={s}
|
||||||
pending={pendingIds.has(s.id)}
|
pending={pendingIds.has(s.id)}
|
||||||
onEdit={() => setEditingId(s.id)}
|
onEdit={() => setEditingId(s.id)}
|
||||||
|
onFireNow={() => fireNow(s)}
|
||||||
onTogglePaused={() => togglePaused(s)}
|
onTogglePaused={() => togglePaused(s)}
|
||||||
onRemove={() => setRemoveTarget(s)}
|
onRemove={() => setRemoveTarget(s)}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
14
frontend/packages/swarm-ui/test/fire-now.test.mjs
Normal file
14
frontend/packages/swarm-ui/test/fire-now.test.mjs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
// The body of a schedule's "fire now". Run by `npm test`.
|
||||||
|
import assert from "node:assert/strict";
|
||||||
|
import { test } from "node:test";
|
||||||
|
import { fireNowBody } from "../src/pages/schedules/ScheduleTypes.ts";
|
||||||
|
|
||||||
|
test("fire now moves the start to the current second", () => {
|
||||||
|
assert.deepEqual(fireNowBody(1_700_000_123_456), {
|
||||||
|
anchor_unix: 1_700_000_123,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("fire now sends nothing but the start", () => {
|
||||||
|
assert.deepEqual(Object.keys(fireNowBody(0)), ["anchor_unix"]);
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue