fix: improve egress and job diagnostics (#969)
Co-authored-by: Codex <codex@noreply.local>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// SPEC: PJ2026-01060509 出站诊断 draft-2026-06-26-p8-egress-job-friction.
|
||||
// Async job state, summaries, and lifecycle drill-down rendering for UniDesk CLI.
|
||||
import { spawn, spawnSync } from "node:child_process";
|
||||
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
@@ -270,6 +272,50 @@ export function renderJobStatusSummary(job: ReturnType<typeof jobWithTail>): Ren
|
||||
};
|
||||
}
|
||||
|
||||
export function renderJobLaunchSummary(command: string, result: unknown): RenderedCliResult | null {
|
||||
if (typeof result !== "object" || result === null || !("job" in result)) return null;
|
||||
const record = result as Record<string, unknown>;
|
||||
const job = record.job as Partial<JobRecord> | undefined;
|
||||
if (typeof job !== "object" || job === null || typeof job.id !== "string") return null;
|
||||
const service = typeof record.service === "string" ? record.service : "-";
|
||||
const runtimeEnv = typeof record.runtimeEnv === "object" && record.runtimeEnv !== null ? record.runtimeEnv as Record<string, unknown> : {};
|
||||
const stdoutFile = typeof job.stdoutFile === "string" ? job.stdoutFile : "-";
|
||||
const stderrFile = typeof job.stderrFile === "string" ? job.stderrFile : "-";
|
||||
const statusCommand = `bun scripts/cli.ts job status ${job.id} --tail-bytes 12000`;
|
||||
const fullCommand = command.includes("--full") || command.includes("--raw") ? null : `bun scripts/cli.ts ${command} --full`;
|
||||
const lines = [
|
||||
"ASYNC_JOB",
|
||||
jobStatusTable(
|
||||
["JOB", "NAME", "STATUS", "SERVICE", "RUNNER", "CREATED"],
|
||||
[[job.id, job.name ?? "-", job.status ?? "-", service, job.runner ?? "-", job.createdAt ?? "-"]],
|
||||
),
|
||||
"",
|
||||
jobStatusTable(
|
||||
["STREAM", "PATH"],
|
||||
[
|
||||
["stdout", stdoutFile],
|
||||
["stderr", stderrFile],
|
||||
["runtimeEnv", typeof runtimeEnv.envFile === "string" ? runtimeEnv.envFile : "-"],
|
||||
["logDir", typeof runtimeEnv.logDir === "string" ? runtimeEnv.logDir : "-"],
|
||||
],
|
||||
),
|
||||
"",
|
||||
"NEXT",
|
||||
` status: ${statusCommand}`,
|
||||
" latest: bun scripts/cli.ts job status latest --tail-bytes 12000",
|
||||
" list: bun scripts/cli.ts job list --limit 20",
|
||||
" logs: bun scripts/cli.ts server logs --tail-bytes 3000",
|
||||
" server: bun scripts/cli.ts server status",
|
||||
fullCommand === null ? null : ` full: ${fullCommand}`,
|
||||
].filter((line): line is string => line !== null);
|
||||
return {
|
||||
ok: job.status !== "failed",
|
||||
command,
|
||||
contentType: "text/plain",
|
||||
renderedText: `${lines.join("\n")}\n`,
|
||||
};
|
||||
}
|
||||
|
||||
function summarizeJobProgress(job: JobRecord, maxBytes = 96_000, tails?: { stdoutTail: string; stderrTail: string }): JobProgressSummary {
|
||||
const nowMs = Date.now();
|
||||
const knownWorkflow = job.name === "hwlab_g14_v02_trigger_current";
|
||||
|
||||
Reference in New Issue
Block a user