feat(platform,datalink,bill): add workflow job drilldown, safe record batch-edit, audit, and spec linkage diagnostics (v0.8.11)
This commit is contained in:
1 parent
2ec08033e0
commit
a0ec7f95a7
37 files changed
+3958
-674
No files matched your search
+466
-15
@@ -7,11 +7,16 @@ import { stringOption, numberOption, booleanOption } from "../parser.js";
|
||||
import { createClientsForCorp, createPiperClientForCorp } from "../helpers.js";
|
||||
import { printJson, printTable, printKeyValue } from "../printer.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
|
||||
import { analyzeWorkflow } from "../../domains/platform/analysis.js";
|
||||
import {
|
||||
analyzeWorkflow,
|
||||
extractWorkflowSpecificationIds,
|
||||
type WorkflowFormSpecLike,
|
||||
} from "../../domains/platform/analysis.js";
|
||||
import { getFormSpecification } from "../../domains/bill/tools.js";
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import { homedir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { WorkflowDetailSchema } from "../../domains/platform/types.js";
|
||||
import { WorkflowDetailSchema, type WorkflowTaskExecution } from "../../domains/platform/types.js";
|
||||
import {
|
||||
createWorkflowDraft,
|
||||
beginWorkflowSave,
|
||||
@@ -24,6 +29,7 @@ import { WorkflowAlertStore } from "../../domains/platform/workflow-alert-store.
|
||||
import { isDryRun, mutationPreview, requireMutationConfirmation } from "../mutation.js";
|
||||
|
||||
const WORKFLOW_STATE_DIR = process.env.HOSE_STATE_DIR || join(homedir(), ".config", "hose-use");
|
||||
const PLATFORM_ID_OPTION_KEYS = ["platform-id", "platformId", "app-id", "appId"];
|
||||
|
||||
export async function handleWorkflowCommand(
|
||||
parsed: CliParsedArgs,
|
||||
@@ -68,6 +74,9 @@ export async function handleWorkflowCommand(
|
||||
case "logs":
|
||||
case "log":
|
||||
return handleLogs(parsed, runtime);
|
||||
case "job":
|
||||
case "execution":
|
||||
return handleJob(parsed, runtime);
|
||||
case "check":
|
||||
case "health":
|
||||
return handleCheck(parsed, runtime);
|
||||
@@ -77,7 +86,7 @@ export async function handleWorkflowCommand(
|
||||
default:
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `未知 workflow 子命令: ${action}。支持: list, get, find, analyze, toggle, publish, patch, save, history, logs, check\n`,
|
||||
stderr: `未知 workflow 子命令: ${action}。支持: list, get, find, analyze, toggle, publish, patch, save, history, logs, job, check\n`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
@@ -226,12 +235,12 @@ async function resolveWorkflowPlatformId(
|
||||
clients: Awaited<ReturnType<typeof createClientsForCorp>>,
|
||||
pipelineId: string
|
||||
): Promise<string> {
|
||||
const explicit = stringOption(parsed.options, ["platform-id", "platformId"]);
|
||||
const explicit = stringOption(parsed.options, PLATFORM_ID_OPTION_KEYS);
|
||||
if (explicit) return explicit;
|
||||
const all = await listAllWorkflows(clients, { page: 1, pageSize: 100 });
|
||||
const match = all.workflows.find((workflow) => workflow.id === pipelineId);
|
||||
if (!match?.platformId) {
|
||||
throw new Error(`无法确定工作流 [${pipelineId}] 所属自建应用,请使用 --platform-id=<platformId>`);
|
||||
throw new Error(`无法确定工作流 [${pipelineId}] 所属自建应用,请使用 --platform-id=<platformId> 或 --app-id=<appId>`);
|
||||
}
|
||||
return match.platformId;
|
||||
}
|
||||
@@ -239,15 +248,36 @@ async function resolveWorkflowPlatformId(
|
||||
async function handleAnalyze(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
const pipelineId = parsed.args[0] || stringOption(parsed.options, ["id", "pipelineId"]);
|
||||
if (!pipelineId) return { stdout: "", stderr: "用法: hose-use workflow analyze <pipelineId>\n", exitCode: 1 };
|
||||
const { client } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
|
||||
const { client, clients } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
|
||||
const detail = await api.getWorkflowDetail(client, pipelineId);
|
||||
const result = analyzeWorkflow(detail);
|
||||
const specIds = extractWorkflowSpecificationIds(detail);
|
||||
const specifications: Record<string, WorkflowFormSpecLike | undefined> = {};
|
||||
if (specIds.length > 0) {
|
||||
const corpId = runtime.selectedCorp!.corpId || runtime.selectedCorp!.id;
|
||||
await Promise.all(
|
||||
specIds.map(async (specId) => {
|
||||
try {
|
||||
const spec = await getFormSpecification(clients.ekbClient, corpId, specId);
|
||||
if (spec) specifications[specId] = spec;
|
||||
} catch {
|
||||
// Ignore specification fetch failure in offline or restricted environments
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
const result = analyzeWorkflow(detail, { specifications });
|
||||
if (runtime.jsonMode) return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
|
||||
const diagnosticRows = result.diagnostics.map((item) => [item.severity, item.code, item.path, item.message]);
|
||||
const dependencyRows = result.dependencies.map((item) => [item.path, item.taskType, item.references.join(", ")]);
|
||||
return { stdout: [
|
||||
`====== 工作流静态分析 (${detail.label || detail.id}) ======`,
|
||||
printKeyValue({ "工作流 ID": detail.id, "根节点数": result.ast.length, "依赖节点数": result.dependencies.length, "诊断数": result.diagnostics.length }),
|
||||
printKeyValue({
|
||||
"工作流 ID": detail.id,
|
||||
"状态": detail.state === 1 ? "🟢 启用 (state=1)" : "⚪ 停用/草稿 (state=0)",
|
||||
"根节点数": result.ast.length,
|
||||
"依赖节点数": result.dependencies.length,
|
||||
"诊断数": result.diagnostics.length,
|
||||
}),
|
||||
`\n依赖引用:\n${dependencyRows.length ? printTable(["节点路径", "类型", "引用"], dependencyRows) : "暂无代码引用"}`,
|
||||
`\n诊断:\n${diagnosticRows.length ? printTable(["级别", "代码", "节点路径", "说明"], diagnosticRows) : "未发现明显配置问题"}`, "",
|
||||
].join("\n"), stderr: "", exitCode: 0 };
|
||||
@@ -277,17 +307,423 @@ async function handleHistory(parsed: CliParsedArgs, runtime: CliRuntime): Promis
|
||||
|
||||
async function handleLogs(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
const pipelineId = parsed.args[0] || stringOption(parsed.options, ["id", "pipelineId"]);
|
||||
if (!pipelineId) return { stdout: "", stderr: "用法: hose-use workflow logs <pipelineId> [--state=FAILED] [--start-time=YYYY-MM-DD] [--end-time=YYYY-MM-DD]\n", exitCode: 1 };
|
||||
if (!pipelineId) return { stdout: "", stderr: "用法: hose-use workflow logs <pipelineId> [--state=FAILED] [--has-error] [--start-time=YYYY-MM-DD] [--end-time=YYYY-MM-DD]\n", exitCode: 1 };
|
||||
const { client } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
|
||||
const result = await api.listWorkflowLogs(client, pipelineId, {
|
||||
const rawResult = await api.listWorkflowLogs(client, pipelineId, {
|
||||
state: stringOption(parsed.options, ["state"]),
|
||||
page: numberOption(parsed.options, ["page"]),
|
||||
pageSize: numberOption(parsed.options, ["page-size", "pageSize", "size"]),
|
||||
startTime: stringOption(parsed.options, ["start-time", "startTime"]),
|
||||
endTime: stringOption(parsed.options, ["end-time", "endTime"]),
|
||||
});
|
||||
const hasErrorFilter = booleanOption(parsed.options, ["has-error", "hasError", "errors"]);
|
||||
const filteredJobList = hasErrorFilter
|
||||
? rawResult.jobList.filter(
|
||||
(job) => job.hasError === true || job.errorTaskCount > 0 || job.state === "FAILED"
|
||||
)
|
||||
: rawResult.jobList;
|
||||
const result = hasErrorFilter
|
||||
? { ...rawResult, jobList: filteredJobList }
|
||||
: rawResult;
|
||||
|
||||
if (runtime.jsonMode) return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
|
||||
return { stdout: `====== 工作流运行日志 [${pipelineId}] ======\n${printKeyValue({ "执行次数": result.executeCount, "成功次数": result.successCount, "错误次数": result.errorCount, "日志条数": result.totalItems, "运行记录": result.jobList.length })}\n${printJson(result, runtime.outputOptions)}\n`, stderr: "", exitCode: 0 };
|
||||
|
||||
const rows = result.jobList.map((job, idx) => [
|
||||
idx + 1,
|
||||
job.id,
|
||||
job.state,
|
||||
job.successTaskCount,
|
||||
job.errorTaskCount,
|
||||
job.hasError || job.errorTaskCount > 0 ? "⚠️ 是 (true)" : "否 (false)",
|
||||
job.durationTime ?? "-",
|
||||
job.startTime || "-",
|
||||
]);
|
||||
const tableStr = rows.length
|
||||
? printTable(
|
||||
["#", "Job ID", "状态 (state)", "成功节点 (successTaskCount)", "失败节点 (errorTaskCount)", "有错误 (hasError)", "耗时(ms)", "开始时间"],
|
||||
rows
|
||||
)
|
||||
: "暂无匹配的运行记录";
|
||||
|
||||
return {
|
||||
stdout: [
|
||||
`====== 工作流运行日志 [${pipelineId}] ======`,
|
||||
printKeyValue({
|
||||
"执行次数": result.executeCount,
|
||||
"成功次数": result.successCount,
|
||||
"错误次数": result.errorCount,
|
||||
"日志条数": result.totalItems,
|
||||
"当前返回记录": result.jobList.length,
|
||||
}),
|
||||
"",
|
||||
tableStr,
|
||||
"\n提示: 运行 hose-use workflow job <jobId> [--failed] 下钻查看单次 Job 节点级报错与入参明细\n",
|
||||
].join("\n"),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
async function createJobPiperClient(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime
|
||||
): Promise<Awaited<ReturnType<typeof createPiperClientForCorp>>> {
|
||||
const corp = runtime.selectedCorp!;
|
||||
const explicit = stringOption(parsed.options, PLATFORM_ID_OPTION_KEYS);
|
||||
if (explicit) {
|
||||
return createPiperClientForCorp(corp, explicit);
|
||||
}
|
||||
const clients = await createClientsForCorp(corp);
|
||||
try {
|
||||
const corpId = corp.corpId || corp.id;
|
||||
const platforms = await api.listPlatforms(clients.ekbClient, corpId);
|
||||
const firstActive = platforms.find((p) => p.active) ?? platforms[0];
|
||||
if (firstActive?.id) {
|
||||
return await createPiperClientForCorp(corp, firstActive.id);
|
||||
}
|
||||
} catch {
|
||||
// Fall back to default easoClient
|
||||
}
|
||||
return clients.easoClient;
|
||||
}
|
||||
|
||||
async function enrichFailedExecutions(
|
||||
client: Awaited<ReturnType<typeof createPiperClientForCorp>>,
|
||||
jobId: string,
|
||||
items: WorkflowTaskExecution[]
|
||||
): Promise<WorkflowTaskExecution[]> {
|
||||
const parentCache = new Map<string, WorkflowTaskExecution[]>();
|
||||
const enriched: WorkflowTaskExecution[] = [];
|
||||
|
||||
for (const item of items) {
|
||||
if (item.parentId && (!item.currentLoopPath || !item.name || !item.form)) {
|
||||
let siblings = parentCache.get(item.parentId);
|
||||
if (!siblings) {
|
||||
try {
|
||||
const level = await api.getJobExecutionLevel(client, jobId, {
|
||||
parentId: item.parentId,
|
||||
page: 1,
|
||||
pageSize: 100,
|
||||
});
|
||||
siblings = level.items;
|
||||
} catch {
|
||||
siblings = [];
|
||||
}
|
||||
parentCache.set(item.parentId, siblings);
|
||||
}
|
||||
const matched = siblings.find((s) => s.id === item.id);
|
||||
if (matched) {
|
||||
const itemInputs = item.inputs;
|
||||
const matchedInputs = matched.inputs;
|
||||
const hasItemInputs = Array.isArray(itemInputs)
|
||||
? itemInputs.length > 0
|
||||
: Boolean(itemInputs && typeof itemInputs === "object" && Object.keys(itemInputs as Record<string, unknown>).length > 0);
|
||||
const itemOutputs = item.outputs;
|
||||
const matchedOutputs = matched.outputs;
|
||||
const hasItemOutputs = Boolean(
|
||||
itemOutputs && typeof itemOutputs === "object" && Object.keys(itemOutputs as Record<string, unknown>).length > 0
|
||||
);
|
||||
enriched.push({
|
||||
...matched,
|
||||
...item,
|
||||
name: item.name || matched.name,
|
||||
label: item.label || matched.label,
|
||||
displayName: item.displayName || matched.displayName,
|
||||
type: item.type || matched.type,
|
||||
status: item.status || matched.status,
|
||||
currentLoopPath: item.currentLoopPath || matched.currentLoopPath,
|
||||
levelIndex: item.levelIndex?.length ? item.levelIndex : matched.levelIndex,
|
||||
form: item.form ?? matched.form,
|
||||
details: item.details ?? matched.details,
|
||||
inputs: hasItemInputs ? itemInputs : matchedInputs,
|
||||
outputs: hasItemOutputs ? itemOutputs : matchedOutputs,
|
||||
error: item.error ?? matched.error,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
}
|
||||
enriched.push(item);
|
||||
}
|
||||
return enriched;
|
||||
}
|
||||
|
||||
async function handleJob(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
const jobId = parsed.args[0] || stringOption(parsed.options, ["id", "job-id", "jobId"]);
|
||||
if (!jobId) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "用法: hose-use workflow job <jobId> [--failed] [--parent=<executionId>] [--logs=<executionId>]\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
const client = await createJobPiperClient(parsed, runtime);
|
||||
const page = numberOption(parsed.options, ["page"]) || 1;
|
||||
const pageSize = numberOption(parsed.options, ["page-size", "pageSize", "size"]) || 100;
|
||||
const logsExecutionId = stringOption(parsed.options, ["logs", "log", "execution-logs"]);
|
||||
const parentExecutionId = stringOption(parsed.options, ["parent", "parent-id", "parentId"]);
|
||||
const onlyFailed = booleanOption(parsed.options, ["failed", "fail", "errors"]);
|
||||
|
||||
// 1. --logs=<executionId>
|
||||
if (logsExecutionId) {
|
||||
const logs = await api.getExecutionLogs(client, logsExecutionId);
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson({ jobId, executionId: logsExecutionId, logs }, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
const rows = logs.map((log, i) => [
|
||||
i + 1,
|
||||
String(log.id ?? "-"),
|
||||
String(log.createAt ?? (log as Record<string, unknown>).createTime ?? (log as Record<string, unknown>).timestamp ?? "-"),
|
||||
String(log.level || "INFO"),
|
||||
String(log.message || JSON.stringify(log)),
|
||||
]);
|
||||
return {
|
||||
stdout: [
|
||||
`====== 节点执行日志 (Job: ${jobId} | Execution: ${logsExecutionId}) ======`,
|
||||
rows.length ? printTable(["#", "日志 ID", "时间", "级别", "内容"], rows) : "该节点暂无输出日志",
|
||||
"",
|
||||
].join("\n"),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// 2. --parent=<executionId>
|
||||
if (parentExecutionId) {
|
||||
const levelPage = await api.getJobExecutionLevel(client, jobId, {
|
||||
parentId: parentExecutionId,
|
||||
page,
|
||||
pageSize,
|
||||
});
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson(
|
||||
{
|
||||
jobId,
|
||||
parentId: parentExecutionId,
|
||||
...levelPage,
|
||||
},
|
||||
runtime.outputOptions
|
||||
),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const rows = levelPage.items.map((item, idx) => [
|
||||
idx + 1,
|
||||
item.id,
|
||||
item.name || "-",
|
||||
item.label || item.displayName || "-",
|
||||
item.type || "-",
|
||||
item.status || "-",
|
||||
item.currentLoopPath || "-",
|
||||
item.error?.message || "-",
|
||||
]);
|
||||
const extraDetails: string[] = [];
|
||||
for (const item of levelPage.items) {
|
||||
if (item.form !== undefined || item.error?.message) {
|
||||
extraDetails.push(
|
||||
`\n── 节点明细 [${item.id}] (${item.name || "-"} | loop=${item.currentLoopPath || "-"} | status=${item.status}) ──`
|
||||
);
|
||||
if (item.error?.message) {
|
||||
extraDetails.push(` 错误原因: ${item.error.message}`);
|
||||
}
|
||||
if (item.form !== undefined) {
|
||||
extraDetails.push(` 传入表单 (form): ${JSON.stringify(item.form)}`);
|
||||
}
|
||||
if (item.details !== undefined) {
|
||||
extraDetails.push(` 明细数据 (details): ${JSON.stringify(item.details)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
stdout: [
|
||||
`====== 子节点执行层级明细 (Job: ${jobId} | Parent: ${parentExecutionId} | 共 ${levelPage.totalItems} 项) ======`,
|
||||
rows.length
|
||||
? printTable(
|
||||
["#", "Execution ID", "节点标识 (name)", "节点名称", "类型 (type)", "状态 (status)", "循环路径 (currentLoopPath)", "错误原因"],
|
||||
rows
|
||||
)
|
||||
: "暂无子节点执行记录",
|
||||
...extraDetails,
|
||||
"",
|
||||
].join("\n"),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// 3. --failed
|
||||
if (onlyFailed) {
|
||||
const [job, failedPage] = await Promise.all([
|
||||
api.getJob(client, jobId).catch(() => undefined),
|
||||
api.getJobFailedExecutions(client, jobId),
|
||||
]);
|
||||
const enrichedItems = await enrichFailedExecutions(client, jobId, failedPage.items);
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson(
|
||||
{
|
||||
jobId,
|
||||
job: job ?? null,
|
||||
totalItems: failedPage.totalItems,
|
||||
items: enrichedItems,
|
||||
},
|
||||
runtime.outputOptions
|
||||
),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const rows = enrichedItems.map((item, idx) => [
|
||||
idx + 1,
|
||||
item.id,
|
||||
item.parentId || "-",
|
||||
item.name || "-",
|
||||
item.type || "-",
|
||||
item.status || "-",
|
||||
item.currentLoopPath || "-",
|
||||
item.error?.message || "-",
|
||||
]);
|
||||
const formSummaries: string[] = [];
|
||||
for (const item of enrichedItems) {
|
||||
if (item.error?.message || item.form !== undefined) {
|
||||
formSummaries.push(
|
||||
`\n── ⚠️ 异常节点 [${item.id}] (${item.name || "-"} | status=${item.status} | loop=${item.currentLoopPath || "-"}) ──`
|
||||
);
|
||||
if (item.error?.message) {
|
||||
formSummaries.push(` 错误详情: ${item.error.message}`);
|
||||
}
|
||||
if (item.form !== undefined) {
|
||||
formSummaries.push(` 表单入参 (form): ${JSON.stringify(item.form)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
stdout: [
|
||||
`====== Job 异常/跳过执行节点明细 (Job: ${jobId}) ======`,
|
||||
job
|
||||
? printKeyValue({
|
||||
"Job ID": job.id,
|
||||
"工作流 ID": job.pipelineId,
|
||||
"Job 状态": job.state ?? job.status,
|
||||
"开始时间": job.startTime || "-",
|
||||
"耗时(ms)": String(job.durationTime ?? "-"),
|
||||
})
|
||||
: "",
|
||||
"",
|
||||
rows.length
|
||||
? printTable(
|
||||
["#", "Execution ID", "Parent ID", "节点标识 (name)", "类型 (type)", "状态 (status)", "循环路径 (currentLoopPath)", "错误原因 (error.message)"],
|
||||
rows
|
||||
)
|
||||
: "未发现异常或报错跳过的执行节点",
|
||||
...formSummaries,
|
||||
"",
|
||||
].filter(Boolean).join("\n"),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// 4. Default mode: Job overview + top-level tree + failed executions
|
||||
const [job, tree, failedPage] = await Promise.all([
|
||||
api.getJob(client, jobId),
|
||||
api.getJobExecutionTree(client, jobId),
|
||||
api.getJobFailedExecutions(client, jobId).catch(() => ({
|
||||
number: 1,
|
||||
size: 100,
|
||||
totalPages: 0,
|
||||
totalItems: 0,
|
||||
items: [] as WorkflowTaskExecution[],
|
||||
})),
|
||||
]);
|
||||
const failedExecutions = await enrichFailedExecutions(client, jobId, failedPage.items);
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson(
|
||||
{
|
||||
jobId,
|
||||
job,
|
||||
executionTree: tree,
|
||||
failedExecutions,
|
||||
},
|
||||
runtime.outputOptions
|
||||
),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const treeRows = tree.map((node, idx) => [
|
||||
idx + 1,
|
||||
node.id,
|
||||
node.name || "-",
|
||||
node.label || node.displayName || "-",
|
||||
node.type || "-",
|
||||
node.status || "-",
|
||||
String((node as Record<string, unknown>).durationTime ?? node.executionTime ?? "-"),
|
||||
node.error?.message || "-",
|
||||
]);
|
||||
|
||||
const failedRows = failedExecutions.map((item, idx) => [
|
||||
idx + 1,
|
||||
item.id,
|
||||
item.parentId || "-",
|
||||
item.name || "-",
|
||||
item.type || "-",
|
||||
item.status || "-",
|
||||
item.currentLoopPath || "-",
|
||||
item.error?.message || "-",
|
||||
]);
|
||||
|
||||
const outLines = [
|
||||
`====== 工作流 Job 执行详情 [${job.id}] ======`,
|
||||
printKeyValue({
|
||||
"Job ID": job.id,
|
||||
"工作流 ID (pipelineId)": job.pipelineId,
|
||||
"Job 状态 (state)": job.state ?? job.status,
|
||||
"开始时间": job.startTime || "-",
|
||||
"结束时间": job.endTime || "-",
|
||||
"耗时(ms)": String(job.durationTime ?? "-"),
|
||||
"顶层节点数": tree.length,
|
||||
"异常/跳过节点数": failedExecutions.length,
|
||||
}),
|
||||
"",
|
||||
"── 顶层节点执行树 ──",
|
||||
treeRows.length
|
||||
? printTable(
|
||||
["#", "Execution ID", "节点标识 (name)", "节点名称", "类型 (type)", "状态 (status)", "耗时(ms)", "错误信息"],
|
||||
treeRows
|
||||
)
|
||||
: "暂无顶层节点执行记录",
|
||||
];
|
||||
|
||||
if (failedRows.length > 0) {
|
||||
outLines.push("");
|
||||
outLines.push("── ⚠️ 失败/报错跳过节点明细 (含循环子项) ──");
|
||||
outLines.push(
|
||||
printTable(
|
||||
["#", "Execution ID", "Parent ID", "节点标识 (name)", "类型 (type)", "状态 (status)", "循环路径 (currentLoopPath)", "错误原因 (error.message)"],
|
||||
failedRows
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
stdout: `${outLines.join("\n")}\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
async function handleCheck(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
@@ -349,8 +785,17 @@ async function handleList(parsed: CliParsedArgs, runtime: CliRuntime): Promise<C
|
||||
const clients = await createClientsForCorp(runtime.selectedCorp!);
|
||||
const page = numberOption(parsed.options, ["page"]) || 1;
|
||||
const pageSize = numberOption(parsed.options, ["pageSize", "size"]) || 50;
|
||||
const filterPlatformId = stringOption(parsed.options, PLATFORM_ID_OPTION_KEYS);
|
||||
|
||||
const result = await listAllWorkflows(clients, { page, pageSize });
|
||||
const rawResult = await listAllWorkflows(clients, { page, pageSize });
|
||||
const workflows = filterPlatformId
|
||||
? rawResult.workflows.filter(
|
||||
(wf) => wf.platformId === filterPlatformId || wf.platformName === filterPlatformId
|
||||
)
|
||||
: rawResult.workflows;
|
||||
const result = filterPlatformId
|
||||
? { ...rawResult, workflows, totalWorkflows: workflows.length }
|
||||
: rawResult;
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
|
||||
@@ -429,15 +874,21 @@ async function createWorkflowDetailClient(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime,
|
||||
pipelineId: string,
|
||||
): Promise<{ client: Awaited<ReturnType<typeof createPiperClientForCorp>> }> {
|
||||
): Promise<{
|
||||
client: Awaited<ReturnType<typeof createPiperClientForCorp>>;
|
||||
clients: Awaited<ReturnType<typeof createClientsForCorp>>;
|
||||
}> {
|
||||
const clients = await createClientsForCorp(runtime.selectedCorp!);
|
||||
const explicit = stringOption(parsed.options, ["platform-id", "platformId"]);
|
||||
const explicit = stringOption(parsed.options, PLATFORM_ID_OPTION_KEYS);
|
||||
let platformId = explicit;
|
||||
if (!platformId) {
|
||||
const all = await listAllWorkflows(clients, { page: 1, pageSize: 100 });
|
||||
platformId = all.workflows.find((workflow) => workflow.id === pipelineId)?.platformId;
|
||||
}
|
||||
return { client: platformId ? await createPiperClientForCorp(runtime.selectedCorp!, platformId) : clients.easoClient };
|
||||
return {
|
||||
client: platformId ? await createPiperClientForCorp(runtime.selectedCorp!, platformId) : clients.easoClient,
|
||||
clients,
|
||||
};
|
||||
}
|
||||
|
||||
async function handleFind(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
|
||||
Reference in new issue
Block a user