diff --git a/packages/core/pipeline/src/core/executor.ts b/packages/core/pipeline/src/core/executor.ts index 694328d5..55f6508c 100644 --- a/packages/core/pipeline/src/core/executor.ts +++ b/packages/core/pipeline/src/core/executor.ts @@ -11,30 +11,29 @@ import { IAccessService } from "../access"; import { RegistryItem } from "../registry"; import { Decorator } from "../decorator"; -export class Executor { +export type ExecutorOptions = { userId: any; pipeline: Pipeline; - runtime!: RunHistory; + storage: IStorage; + onChanged: (history: RunHistory) => Promise; accessService: IAccessService; +}; +export class Executor { + pipeline: Pipeline; + runtime!: RunHistory; contextFactory: ContextFactory; logger: Logger; pipelineContext!: IContext; lastStatusMap!: RunnableCollection; + options: ExecutorOptions; onChanged: (history: RunHistory) => void; - constructor(options: { - userId: any; - pipeline: Pipeline; - storage: IStorage; - onChanged: (history: RunHistory) => Promise; - accessService: IAccessService; - }) { + constructor(options: ExecutorOptions) { + this.options = options; this.pipeline = _.cloneDeep(options.pipeline); this.onChanged = async (history: RunHistory) => { await options.onChanged(history); }; - this.accessService = options.accessService; - this.userId = options.userId; - this.pipeline.userId = this.userId; + this.pipeline.userId = options.userId; this.contextFactory = new ContextFactory(options.storage); this.logger = logger; this.pipelineContext = this.contextFactory.getContext("pipeline", this.pipeline.id); @@ -183,10 +182,10 @@ export class Executor { const context: any = { logger: this.runtime._loggers[step.id], - accessService: this.accessService, + accessService: this.options.accessService, pipelineContext: this.pipelineContext, lastStatus, - userContext: this.contextFactory.getContext("user", this.userId), + userContext: this.contextFactory.getContext("user", this.options.userId), http: request, }; Decorator.inject(define.autowire, instance, context); diff --git a/packages/core/pipeline/src/d.ts/pipeline.ts b/packages/core/pipeline/src/d.ts/pipeline.ts index 6d7b0bb0..af19c9d4 100644 --- a/packages/core/pipeline/src/d.ts/pipeline.ts +++ b/packages/core/pipeline/src/d.ts/pipeline.ts @@ -66,11 +66,23 @@ export type Runnable = { }; }; +export type EmailOptions = { + receivers: string[]; +}; +export type NotificationWhen = "error" | "success" | "start"; +export type NotificationType = "email" | "url"; +export type Notification = { + type: NotificationType; + when: NotificationWhen[]; + options: EmailOptions; +}; + export type Pipeline = Runnable & { version?: number; userId: any; stages: Stage[]; triggers: Trigger[]; + notifications: Notification[]; }; export type Context = {