feat(platform): 支持工作流单号本地缓存秒级定位与自建应用业务对象智能反查
- 数据库迁移与本地缓存:在 `core/db/migrations.ts` 新增 version 5 迁移 (`005_workflow_job_cache`),创建 `workflow_job_index` 缓存表及高效复合索引;实现 `core/db/workflow-job-cache.ts`,支持按企业+工作流+单号快速检索与幂等增量缓存; - 流式早停探查与业务编排:在 `domains/platform/workflow/execution/search-by-flow.ts` 实现 `searchWorkflowJobByFlowCode`,采用「本地 SQLite 缓存 0ms 直达 ➔ 远端流式探查早停熔断并自动建立本地索引」机制,彻底解决云端 Piper API 无单号索引导致的排查低效问题; - CLI 命令层升级: - `workflow logs <pipelineId> --flow=<单号>`:直接秒级定位单据关联 Job 实例; - `platform records <业务对象>`:支持单参数业务对象名称,自动在企业全量自建应用中全局反查与智能寻址,若跨应用重名则抛出精准候选; - 命令行元数据对齐:在 `command-metadata.ts` 为 `workflow` 补齐 `--max-pages`、`--maxPages` 与 `--page-limit` 选项注册,满足严格参数词汇表静态检查; - 测试与文档:新增并更新 `workflow-job-cache.test.ts`、`search-by-flow.test.ts`、`platform.test.ts` 与 `db.test.ts`,更新核心与域层文档,全量 1126 个测试与类型检查全部通过。
This commit is contained in:
1 parent
ea5eb22c51
commit
0c9eb27f85
16 files changed
+798
-19
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { getWorkflowDetail, listWorkflowLogs, listWorkflowSnapshots } from "../../../domains/platform/workflow/services.js";
|
||||
import { getWorkflowDetail, listWorkflowLogs, listWorkflowSnapshots, searchWorkflowJobByFlowCode } from "../../../domains/platform/workflow/services.js";
|
||||
import { stringOption, numberOption, booleanOption } from "../../parser.js";
|
||||
import { printJson, printTable, printKeyValue } from "../../printer.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
||||
@@ -28,8 +28,52 @@ export async function handleHistory(parsed: CliParsedArgs, runtime: CliRuntime):
|
||||
|
||||
export 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] [--has-error] [--start-time=YYYY-MM-DD] [--end-time=YYYY-MM-DD]\n", exitCode: 1 };
|
||||
if (!pipelineId) return { stdout: "", stderr: "用法: hose-use workflow logs <pipelineId> [--flow=<单号>] [--state=FAILED] [--has-error] [--start-time=YYYY-MM-DD] [--end-time=YYYY-MM-DD]\n", exitCode: 1 };
|
||||
const { client } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
|
||||
|
||||
// 优先支持按单号精准定位 Job(本地 SQLite 缓存秒级直达 + 流式熔断探查)
|
||||
const flowFilter = stringOption(parsed.options, ["flow", "flowCode", "code"]);
|
||||
if (flowFilter) {
|
||||
const corpId = runtime.selectedCorp?.credentials.corpId || "";
|
||||
const searchResult = await searchWorkflowJobByFlowCode(client, corpId, pipelineId, flowFilter, {
|
||||
maxScanPages: numberOption(parsed.options, ["max-pages", "maxPages", "page-limit"]) ?? 10,
|
||||
});
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson(searchResult, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: searchResult.found ? 0 : 1,
|
||||
};
|
||||
}
|
||||
|
||||
if (!searchResult.found) {
|
||||
return {
|
||||
stdout: `未找到单号 [${flowFilter}] 对应的工作流执行记录 (已探查 ${searchResult.totalScanned || 0} 笔 Job)\n`,
|
||||
stderr: "",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
const job = searchResult.job!;
|
||||
const hitInfo = searchResult.source === "cache" ? "⚡ 本地 SQLite 缓存秒级命中" : "🔍 远端流式探查并自动建立本地缓存";
|
||||
const out = [
|
||||
`====== 工作流单据定位成功 [${pipelineId}] ======`,
|
||||
printKeyValue({
|
||||
"定位来源": hitInfo,
|
||||
"触发单号": searchResult.flowCode || "-",
|
||||
"实例 ID (jobId)": job.id,
|
||||
"运行状态 (status)": job.status || "-",
|
||||
"提交人": job.inputs?.userInfo?.name || "-",
|
||||
"创建时间": job.createTime ? new Date(job.createTime).toLocaleString() : "-",
|
||||
}),
|
||||
"",
|
||||
`提示: 可执行 hose-use workflow job ${job.id} 查看该单据的完整节点执行树与代码运算日志。`,
|
||||
].join("\n");
|
||||
|
||||
return { stdout: `${out}\n`, stderr: "", exitCode: 0 };
|
||||
}
|
||||
|
||||
const rawResult = await listWorkflowLogs(client, pipelineId, {
|
||||
state: stringOption(parsed.options, ["state"]),
|
||||
page: numberOption(parsed.options, ["page"]),
|
||||
|
||||
Reference in new issue
Block a user