RYP-E4, dispatch 4.2 PY2.2 (Railyard side): - lib/watch: checks (public https app addresses only; IPs, private names and our own hosts refused), 20 per org, a status page slug each. The box 1 agent reads GET /api/v1/watch/agent/checks (ids and URLs only, bearer WATCH_AGENT_TOKEN) and posts results to /api/v1/watch/agent/results. Two failures in a row turn a check red; each change emails the owner once through Rally Send (product railyard, from status@, idempotency key per change; a failed send is retried on the next result). Older, unknown and future results change nothing. - /status/<slug>: live results only (state, share of the last checks, bars), the check's name and never its address or any host or vendor name. - The Watch screen: add by address, pause or resume, open the status page. - Bridge route uptime (contract cases, uptime_check_keys): a check for the given address, or the app's latest live deploy; the first result is the slot's proof (check_result). - Gated on RAILYARD_WATCH_LIVE (denylist rule railyard-slot-watch): off, no check runs, the pages 404, the nav has no Watch item and the slot answers arriving. The copy test lints each gated surface with the flag and proves it checks the flag first. - Migration 0006 (watch_checks, watch_status; https only, history capped at 90, cascades with the org). Tests: watch 10/10, bridge 25/25, contract 3/3, migration 7/7 (0006 twice on a scratch cluster), watch copy 7/7, console 108/108 with the bundle build, tsc clean, SDK 7/7. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
91 lines
3.0 KiB
TypeScript
91 lines
3.0 KiB
TypeScript
"use client";
|
|
import { useRouter } from "next/navigation";
|
|
import { useState } from "react";
|
|
|
|
export interface PanelCheck {
|
|
id: string;
|
|
app: string;
|
|
name: string;
|
|
url: string;
|
|
paused: boolean;
|
|
state: string;
|
|
status_url: string;
|
|
last_checked_at: string | null;
|
|
}
|
|
|
|
async function post(body: Record<string, unknown>): Promise<string | null> {
|
|
const res = await fetch("/api/watch", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) });
|
|
if (res.ok) return null;
|
|
return ((await res.json().catch(() => ({}))) as { error?: string }).error ?? "Could not save. Try again.";
|
|
}
|
|
|
|
const LABEL: Record<string, string> = { up: "Up", down: "Down", waiting: "Waiting" };
|
|
|
|
/** Uptime checks: add one by address, pause or resume, open the status page (PY2.2). */
|
|
export function WatchPanel({ apps, checks }: { apps: string[]; checks: PanelCheck[] }) {
|
|
const router = useRouter();
|
|
const [app, setApp] = useState(apps[0] ?? "");
|
|
const [url, setUrl] = useState("");
|
|
const [busy, setBusy] = useState(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const run = async (body: Record<string, unknown>) => {
|
|
setBusy(true);
|
|
setError(null);
|
|
const e = await post(body);
|
|
setBusy(false);
|
|
if (e) setError(e);
|
|
else {
|
|
setUrl("");
|
|
router.refresh();
|
|
}
|
|
};
|
|
return (
|
|
<>
|
|
{checks.length ? (
|
|
<ul className="list">
|
|
{checks.map((c) => (
|
|
<li key={c.id}>
|
|
<span>
|
|
<strong>{c.name}</strong> <span className="muted">{c.url}</span>
|
|
</span>
|
|
<span className="row">
|
|
<span className={c.state === "down" ? "error" : c.state === "up" ? "ok" : "muted"}>{c.paused ? "Paused" : LABEL[c.state] ?? c.state}</span>
|
|
<a href={c.status_url}>Status page</a>
|
|
<button type="button" disabled={busy} onClick={() => run({ id: c.id, paused: !c.paused })}>
|
|
{c.paused ? "Resume" : "Pause"}
|
|
</button>
|
|
</span>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
) : (
|
|
<p className="muted">No checks yet. Add your app's address; we check it every minute.</p>
|
|
)}
|
|
{apps.length ? (
|
|
<form
|
|
className="row"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
void run({ app, url });
|
|
}}
|
|
>
|
|
<select aria-label="App" value={app} onChange={(e) => setApp(e.target.value)}>
|
|
{apps.map((a) => (
|
|
<option key={a} value={a}>
|
|
{a}
|
|
</option>
|
|
))}
|
|
</select>
|
|
<input type="url" aria-label="Address to check" placeholder="https://your-app.example.com" value={url} onChange={(e) => setUrl(e.target.value)} />
|
|
<button className="primary" type="submit" disabled={busy || !url.trim()}>
|
|
{busy ? "Adding" : "Add check"}
|
|
</button>
|
|
</form>
|
|
) : (
|
|
<p className="muted">Add an app first.</p>
|
|
)}
|
|
{error ? <p className="error">{error}</p> : null}
|
|
</>
|
|
);
|
|
}
|