Files
hose-use/src/cli/commands/workflow/job-execution.ts
T

64 lines
2.5 KiB
TypeScript

import { getJobExecutionLevel } from "../../../domains/platform/workflow/services.js";
import type { WorkflowTaskExecution } from "../../../domains/platform/workflow/types.js";
import type { createPiperClientForCorp } from "../../helpers.js";
export 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 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;
}