refactor: 拆分应用平台服务职责并固化无环边界
将工作流查询、配置、执行、差异、调试、目录和 DataLink 记录、表达式、审计分别归位。 门面保留显式导出,消除 tracker 及分支类型经聚合出口形成的循环,补充文件级循环检查。 同步总纲、层级文档与接口源码索引,交付完整整改报告。 验证:943 项测试通过,类型、版本和 README 审计通过;二进制和插件构建、验证与打包通过。 81 个迁移函数体保持一致,公共 SDK 导出名和三份生成规范与原始基线一致。
This commit is contained in:
1 parent
4e03c9bcd7
commit
a2cdefb322
27 files changed
+2811
-2511
No files matched your search
@@ -0,0 +1,206 @@
|
||||
import { listBasicPlatforms } from "../applications/services.js";
|
||||
import { KyInstance } from "ky";
|
||||
import { CorpConfig } from "../../../core/config/types.js";
|
||||
import * as api from "./api.js";
|
||||
import { WorkflowSummary, WorkflowListAllError, WorkflowTask, WorkflowWithMatches, TaskMatch } from "./types.js";
|
||||
|
||||
|
||||
export interface WorkflowClients {
|
||||
corp: CorpConfig;
|
||||
ekbClient: KyInstance;
|
||||
easoClient: KyInstance;
|
||||
}
|
||||
|
||||
|
||||
export function listWorkflows(...args: Parameters<typeof api.listWorkflows>) {
|
||||
return api.listWorkflows(...args);
|
||||
}
|
||||
|
||||
|
||||
export function getWorkflowStats(...args: Parameters<typeof api.getWorkflowStats>) {
|
||||
return api.getWorkflowStats(...args);
|
||||
}
|
||||
|
||||
|
||||
export function getWorkflowCharge(...args: Parameters<typeof api.getWorkflowCharge>) {
|
||||
return api.getWorkflowCharge(...args);
|
||||
}
|
||||
|
||||
|
||||
export function getWorkflowDetail(...args: Parameters<typeof api.getWorkflowDetail>) {
|
||||
return api.getWorkflowDetail(...args);
|
||||
}
|
||||
|
||||
|
||||
export function listWorkflowSnapshots(...args: Parameters<typeof api.listWorkflowSnapshots>) {
|
||||
return api.listWorkflowSnapshots(...args);
|
||||
}
|
||||
|
||||
|
||||
export function getWorkflowSnapshot(...args: Parameters<typeof api.getWorkflowSnapshot>) {
|
||||
return api.getWorkflowSnapshot(...args);
|
||||
}
|
||||
|
||||
|
||||
export function listWorkflowLogs(...args: Parameters<typeof api.listWorkflowLogs>) {
|
||||
return api.listWorkflowLogs(...args);
|
||||
}
|
||||
|
||||
|
||||
export function listRunningJobs(...args: Parameters<typeof api.listRunningJobs>) {
|
||||
return api.listRunningJobs(...args);
|
||||
}
|
||||
|
||||
|
||||
export function getJob(...args: Parameters<typeof api.getJob>) {
|
||||
return api.getJob(...args);
|
||||
}
|
||||
|
||||
|
||||
export function getJobExecutionTree(...args: Parameters<typeof api.getJobExecutionTree>) {
|
||||
return api.getJobExecutionTree(...args);
|
||||
}
|
||||
|
||||
|
||||
export function getJobFailedExecutions(...args: Parameters<typeof api.getJobFailedExecutions>) {
|
||||
return api.getJobFailedExecutions(...args);
|
||||
}
|
||||
|
||||
|
||||
export function getJobExecutionLevel(...args: Parameters<typeof api.getJobExecutionLevel>) {
|
||||
return api.getJobExecutionLevel(...args);
|
||||
}
|
||||
|
||||
|
||||
export function getExecutionLogs(...args: Parameters<typeof api.getExecutionLogs>) {
|
||||
return api.getExecutionLogs(...args);
|
||||
}
|
||||
|
||||
|
||||
// ── 服务层:跨应用聚合 ───────────────────────────────────────────────────────
|
||||
|
||||
export interface ListAllWorkflowsOptions {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
}
|
||||
|
||||
|
||||
export interface ListAllWorkflowsResult {
|
||||
workflows: WorkflowSummary[];
|
||||
errors: WorkflowListAllError[];
|
||||
}
|
||||
|
||||
|
||||
export async function listAllWorkflows(
|
||||
clients: WorkflowClients,
|
||||
options: ListAllWorkflowsOptions = {}
|
||||
): Promise<ListAllWorkflowsResult> {
|
||||
const { ekbClient, easoClient, corp } = clients;
|
||||
const page = options.page ?? 1;
|
||||
const pageSize = options.pageSize ?? 20;
|
||||
|
||||
const platforms = await listBasicPlatforms(ekbClient, corp.credentials.corpId);
|
||||
const enabledPlatforms = platforms.filter((p) => p.active !== false);
|
||||
|
||||
const workflows: WorkflowSummary[] = [];
|
||||
const errors: WorkflowListAllError[] = [];
|
||||
|
||||
await Promise.all(
|
||||
enabledPlatforms.map(async (platform) => {
|
||||
try {
|
||||
const pageResult = await api.listWorkflows(
|
||||
easoClient,
|
||||
platform.id,
|
||||
page,
|
||||
pageSize
|
||||
);
|
||||
for (const workflow of pageResult.pipelineList) {
|
||||
workflows.push({
|
||||
...workflow,
|
||||
platformId: platform.id,
|
||||
platformName: platform.name,
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
errors.push({
|
||||
platformId: platform.id,
|
||||
platformName: platform.name,
|
||||
error: err instanceof Error ? err.message : String(err),
|
||||
});
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
return { workflows, errors };
|
||||
}
|
||||
|
||||
|
||||
function collectTasksByType(
|
||||
tasks: WorkflowTask[],
|
||||
taskType: string,
|
||||
matches: TaskMatch[] = []
|
||||
): TaskMatch[] {
|
||||
for (const task of tasks) {
|
||||
if (task.type === taskType) {
|
||||
matches.push({
|
||||
taskName: task.name,
|
||||
taskType: task.type,
|
||||
levelIndex: task.levelIndex,
|
||||
});
|
||||
}
|
||||
if ("tasks" in task && Array.isArray(task.tasks)) {
|
||||
collectTasksByType(task.tasks as WorkflowTask[], taskType, matches);
|
||||
}
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
|
||||
|
||||
export interface FindWorkflowsByTaskTypeOptions extends ListAllWorkflowsOptions {
|
||||
includeDetail?: boolean;
|
||||
}
|
||||
|
||||
|
||||
export interface FindWorkflowsByTaskTypeResult {
|
||||
workflows: WorkflowWithMatches[];
|
||||
errors: WorkflowListAllError[];
|
||||
}
|
||||
|
||||
|
||||
export async function findWorkflowsByTaskType(
|
||||
clients: WorkflowClients,
|
||||
taskType: string,
|
||||
options: FindWorkflowsByTaskTypeOptions = {}
|
||||
): Promise<FindWorkflowsByTaskTypeResult> {
|
||||
const { easoClient } = clients;
|
||||
const { includeDetail, ...listOptions } = options;
|
||||
|
||||
const all = await listAllWorkflows(clients, listOptions);
|
||||
const matched: WorkflowWithMatches[] = [];
|
||||
const detailErrors: WorkflowListAllError[] = [];
|
||||
|
||||
for (const workflow of all.workflows) {
|
||||
let tasks = workflow.tasks;
|
||||
|
||||
if (includeDetail) {
|
||||
try {
|
||||
const detail = await api.getWorkflowDetail(easoClient, workflow.id);
|
||||
tasks = detail.tasks;
|
||||
} catch (err) {
|
||||
detailErrors.push({
|
||||
platformId: workflow.platformId,
|
||||
platformName: workflow.platformName,
|
||||
error: err instanceof Error ? err.message : String(err),
|
||||
});
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
const matchedTasks = collectTasksByType(tasks, taskType);
|
||||
if (matchedTasks.length > 0) {
|
||||
matched.push({ ...workflow, matchedTasks });
|
||||
}
|
||||
}
|
||||
|
||||
return { workflows: matched, errors: [...all.errors, ...detailErrors] };
|
||||
}
|
||||
Reference in new issue
Block a user