Files
events-hub/frontend/src/app/(hub)/jobs/[id]/page.tsx
T
joshuaandClaude Opus 5.5 c8359c77e9 Servers and the agent, dashboard (2.1.0): servers, installs, updates, jobs, ports, download page
- Servers: add with a one-time join command, each server's CPU / RAM
  charts (24 h, 7 days, 90 days, spikes over 85% marked, table view),
  configuration, PM2 processes, sites, jobs and alerts.
- Installs: New install (server chooser with free RAM, CPU and sites),
  Link existing, FastPanel steps and Proxy done, schedule / emergency
  update, adopt, uninstall (2FA and the short name).
- Updates: one release to many installs (a batch), planned jobs.
- Jobs with their reports; Ports & defaults; the public download page
  that decrypts an export in the browser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 13:18:20 +02:00

68 lines
4.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import React, { useCallback, useEffect, useState } from "react";
import Link from "next/link";
import { useParams } from "next/navigation";
import { api, errorText } from "@/lib/api";
import { fmtDate } from "@/lib/format";
import { Loading, Message, PageTitle } from "@/components/ui";
import { ServersNav, StatusPill, type Job } from "@/components/servers";
type Msg = { type: "ok" | "err"; text: string } | null;
const OUTCOME: Record<string, string> = { ok: "✓", failed: "✗", skipped: "–", "rolled-back": "↺" };
/** One job and its full report: steps, result and the last log lines (§11). */
export default function JobPage() {
const { id } = useParams<{ id: string }>();
const [job, setJob] = useState<Job | null>(null);
const [msg, setMsg] = useState<Msg>(null);
const load = useCallback(() => api<{ job: Job }>(`/api/admin/jobs/${id}`).then(r => setJob(r.job)).catch(e => setMsg({ type: "err", text: errorText(e) })), [id]);
useEffect(() => {
load();
const t = setInterval(() => { if (!job || ["queued", "delivered", "scheduled"].includes(job.status)) load(); }, 10000);
return () => clearInterval(t);
}, [load, job]);
const post = async (path: string, ok: string) => {
try { await api(path, { method: "POST", body: {} }); setMsg({ type: "ok", text: ok }); load(); } catch (e) { setMsg({ type: "err", text: errorText(e) }); }
};
if (!job) return <div><ServersNav active="/jobs" />{msg ? <Message msg={msg} /> : <Loading />}</div>;
const r = job.report;
return (
<div className="space-y-6">
<div>
<PageTitle title={`${job.type}${job.deployment ? `: ${job.deployment.shortName}` : ""}`} subtitle={<>on <Link className="text-indigo-700 hover:underline" href={`/servers/${job.serverId}`}>{job.server?.name}</Link> · {job.id} <StatusPill status={job.status} /></>}
actions={<div className="flex gap-2">
{["queued", "scheduled"].includes(job.status) && <button className="btn-secondary" onClick={() => post(`/api/admin/jobs/${job.id}/cancel`, "Cancelled.")}>Cancel</button>}
{job.type === "purge" && job.status === "queued" && job.message !== "extended" && <button className="btn-secondary" onClick={() => post(`/api/admin/jobs/${job.id}/extend`, "Put off by 30 days.")}>Keep 30 days longer</button>}
</div>} />
<ServersNav active="/jobs" />
<Message msg={msg} />
</div>
<div className="card grid gap-2 text-sm md:grid-cols-2">
<div><span className="text-slate-500">Window:</span> {fmtDate(job.notBefore)} – {fmtDate(job.expiresAt)}</div>
<div><span className="text-slate-500">Handed to the agent:</span> {fmtDate(job.deliveredAt)}</div>
<div><span className="text-slate-500">Finished:</span> {fmtDate(job.finishedAt)}</div>
{job.reason && <div><span className="text-slate-500">Reason:</span> {job.reason}</div>}
{job.message && <div className="md:col-span-2"><span className="text-slate-500">Result:</span> {job.message}</div>}
<div className="md:col-span-2"><span className="text-slate-500">Arguments:</span> <code className="text-xs">{JSON.stringify(job.args)}</code></div>
</div>
{r && (
<>
<div className="card">
<h2 className="font-medium">Steps</h2>
<ol className="mt-3 space-y-1 text-sm">
{r.steps.map((s, i) => <li key={i} className={s.outcome === "failed" ? "text-red-700" : ""}><span className="inline-block w-5" aria-label={s.outcome}>{OUTCOME[s.outcome] || "•"}</span>{s.name}{s.detail && <span className="text-xs text-slate-500"> ({s.detail})</span>}</li>)}
{!r.steps.length && <li className="text-slate-500">No steps reported.</li>}
</ol>
</div>
{Object.keys(r.result || {}).length > 0 && <div className="card"><h2 className="font-medium">Result</h2><pre className="mt-3 overflow-x-auto text-xs">{JSON.stringify(r.result, null, 2)}</pre></div>}
<div className="card"><h2 className="font-medium">Last log lines</h2><pre className="mt-3 max-h-96 overflow-auto rounded-lg bg-slate-900 p-3 text-xs text-slate-100">{(r.log || []).join("\n") || "(none)"}</pre></div>
</>
)}
</div>
);
}