import { useConsole } from "../context"; import { Card, Bar, DataListRaw } from "../components/ui"; import { workerAgeText, shortId } from "../api/client"; import { chvAvailability, chvAvailabilityText } from "../api/chv"; export default function WorkersSection() { const ctx = useConsole(); const chvAvail = chvAvailability(ctx.workers, ctx.workersSummary, ctx.workersError); return (
{chvAvailabilityText(chvAvail)}
{ctx.workersError ?
{ctx.workersError}
: ctx.workers === null ?
{ctx.workersSummary || "未加载"}
: ctx.workers.length === 0 ?
无 worker 注册
: ( {ctx.workers.map((w, i) => { const run = w.running === undefined || w.running === null ? "?" : w.running; const cap = w.capacity === undefined || w.capacity === null ? "?" : w.capacity; const info = workerAgeText(w); const alive = w.alive !== undefined && w.alive !== null ? !!w.alive : (info.age !== null && info.age <= 120); const live = alive ? " / 在线" : " / 离线(占用为上次上报值)"; return (
  • {w.worker_id || w.id || "?"} / {w.executor || ""} / 占用 {run}/{cap}{live} / 最后心跳 {info.text}
  • ); })}
    )}
    ); }