perf: 优化流水线执行时的状态保存性能

This commit is contained in:
xiaojunnuo
2026-04-28 00:33:59 +08:00
parent 00e6d580c2
commit e00830bebc
3 changed files with 51 additions and 6 deletions
+7 -3
View File
@@ -23,6 +23,7 @@ export type ExecutorOptions = {
pipeline: Pipeline;
storage: IStorage;
onChanged: (history: RunHistory) => Promise<void>;
onFinished: (history: RunHistory) => Promise<void>;
accessService: IAccessService;
emailService: IEmailService;
notificationService: INotificationService;
@@ -47,16 +48,19 @@ export class Executor {
lastRuntime!: RunHistory;
options: ExecutorOptions;
abort: AbortController = new AbortController();
_inited = false;
onChanged: (history: RunHistory) => Promise<void>;
onFinished: (history: RunHistory) => Promise<void>;
constructor(options: ExecutorOptions) {
this.options = options;
this.pipeline = cloneDeep(options.pipeline);
this.onChanged = async (history: RunHistory) => {
await options.onChanged(history);
};
this.onFinished = async (history: RunHistory) => {
await options.onFinished(history);
};
this.pipeline.userId = options.user.id;
this.contextFactory = new ContextFactory(options.storage);
this.logger = logger;
@@ -77,7 +81,7 @@ export class Executor {
async cancel() {
this.abort.abort();
this.runtime?.cancel(this.pipeline);
await this.onChanged(this.runtime);
await this.onFinished(this.runtime);
}
async run(runtimeId: any = 0, triggerType: string) {
@@ -111,7 +115,7 @@ export class Executor {
this.logger.error("pipeline 执行失败", e);
} finally {
clearInterval(intervalFlushLogId);
await this.onChanged(this.runtime);
await this.onFinished(this.runtime);
//保存之前移除logs
const lastRuntime: any = {
...this.runtime,