fleet(tower): 0.20 — Re-Dispatch-Provenienz sichtbar (Badge statt Doppel-Button)

Dead-Letter-Zeile mit re_dispatched_to zeigt '↻ zugestellt <id>' statt des
Aktions-Buttons; Spool-Zeilen mit re_dispatch_of tragen ein ↻ vor dem Topic.
TaskEnvelope um re_dispatch_of/re_dispatched_to erweitert.
This commit is contained in:
Hermes CEO
2026-10-30 06:12:00 +00:00
parent 9e94512214
commit e9c8b14ee6
3 changed files with 109 additions and 3 deletions
+104 -2
View File
@@ -33,6 +33,8 @@ type TaskEnvelope = {
vs: string
claimed_at: string
status_label: string
re_dispatched_to: string
re_dispatch_of: string
file: string
}
@@ -116,6 +118,7 @@ export default function TaskBrowser() {
const [detail, setDetail] = useState<TaskDetail | null>(null)
const [detailLoading, setDetailLoading] = useState(false)
const [detailError, setDetailError] = useState("")
const [redis, setRedis] = useState<Record<string, { state: string; msg: string }>>({})
const modalRef = useRef<HTMLDivElement | null>(null)
const load = useCallback(async () => {
@@ -139,6 +142,46 @@ export default function TaskBrowser() {
return () => clearInterval(t)
}, [load])
/** Dead-Letter-Re-Dispatch: neuer Envelope ueber den board-service (Tower schreibt nie selbst). */
const redispatch = useCallback(
async (taskId: string) => {
setRedis((prev) => ({ ...prev, [taskId]: { state: "busy", msg: "stelle zu…" } }))
try {
const res = await fetch("/api/fleet/task-redispatch", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ id: taskId }),
})
const body = (await res.json()) as {
result?: string
new_task_id?: string
reason?: string
problems?: string[]
}
const result = String(body.result || `HTTP ${res.status}`)
let state = "err"
let msg = result
if (result === "OK_REDISPATCHED") {
state = "ok"
msg = `erneut zugestellt -> ${body.new_task_id}`
} else if (result === "OK_ALREADY") {
state = "already"
msg = `bereits re-dispatched -> ${body.new_task_id || "?"}`
} else if (body.reason || body.problems?.length) {
msg = `${result}: ${body.reason || body.problems?.join("; ")}`
}
setRedis((prev) => ({ ...prev, [taskId]: { state, msg } }))
await load()
} catch (e) {
setRedis((prev) => ({
...prev,
[taskId]: { state: "err", msg: e instanceof Error ? e.message : String(e) },
}))
}
},
[load]
)
const openDetail = useCallback(async (id: string, kind: string) => {
setDetailLoading(true)
setDetailError("")
@@ -267,7 +310,8 @@ export default function TaskBrowser() {
<th className="py-2 pr-3">Typ</th>
<th className="py-2 pr-3">Prio</th>
<th className="py-2 pr-3">Status</th>
<th className="py-2">Thema</th>
<th className="py-2 pr-3">Thema</th>
{tab === "dead-letter" && <th className="py-2">Aktion</th>}
</tr>
</thead>
<tbody className="font-mono">
@@ -290,13 +334,71 @@ export default function TaskBrowser() {
<td className={`py-1.5 pr-3 ${prioClass(t.priority)}`}>{t.priority}</td>
<td className="py-1.5 pr-3">{t.status_label}</td>
<td className="py-1.5 max-w-[26rem] truncate" title={t.topic}>
{t.re_dispatch_of !== "-" && t.re_dispatch_of !== "" && (
<span
className="mr-1 text-[var(--foreground-dim)]"
title={`Re-Dispatch von ${t.re_dispatch_of}`}
data-testid={`redispatch-of-${t.task_id}`}
>
↻
</span>
)}
{t.topic}
</td>
{tab === "dead-letter" && (
<td className="py-1.5 whitespace-nowrap" data-testid={`redispatch-${t.task_id}`}>
{t.re_dispatched_to !== "-" && t.re_dispatched_to !== "" ? (
<span
className="text-[var(--foreground-dim)]"
title={`Bereits erneut zugestellt an ${t.re_dispatched_to}`}
data-testid={`redispatch-already-${t.task_id}`}
>
↻ zugestellt {t.re_dispatched_to.slice(0, 8)}
</span>
) : redis[t.task_id] ? (
<span
className={
redis[t.task_id].state === "ok"
? "text-emerald-400"
: redis[t.task_id].state === "already"
? "text-[var(--foreground-dim)]"
: redis[t.task_id].state === "busy"
? "text-[var(--foreground-dim)]"
: "text-red-400"
}
title={redis[t.task_id].msg}
>
{redis[t.task_id].state === "ok"
? "✔ "
: redis[t.task_id].state === "already"
? "✔ "
: redis[t.task_id].state === "busy"
? "… "
: "✖ "}
{redis[t.task_id].msg.slice(0, 42)}
</span>
) : (
<button
type="button"
className="rounded border border-[var(--border)] px-2 py-0.5 text-[11px] hover:bg-[var(--background-tertiary)]"
onClick={(e) => {
e.stopPropagation()
void redispatch(t.task_id)
}}
>
Erneut zustellen
</button>
)}
</td>
)}
</tr>
))}
{data && ((tab === "spool" ? data.spool : data.dead_letter).length === 0) && (
<tr>
<td colSpan={7} className="py-4 text-[var(--foreground-dim)]">
<td
colSpan={tab === "dead-letter" ? 8 : 7}
className="py-4 text-[var(--foreground-dim)]"
>
{tab === "spool"
? "Keine offenen Tasks — Spool leer."
: "Keine fehlgeschlagenen Tasks in den letzten 7 Tagen."}