mirror of https://github.com/certd/certd
chore: 1
parent
f516b0931f
commit
4c324960e6
|
@ -11,30 +11,29 @@ import { IAccessService } from "../access";
|
||||||
import { RegistryItem } from "../registry";
|
import { RegistryItem } from "../registry";
|
||||||
import { Decorator } from "../decorator";
|
import { Decorator } from "../decorator";
|
||||||
|
|
||||||
export class Executor {
|
export type ExecutorOptions = {
|
||||||
userId: any;
|
userId: any;
|
||||||
pipeline: Pipeline;
|
pipeline: Pipeline;
|
||||||
runtime!: RunHistory;
|
storage: IStorage;
|
||||||
|
onChanged: (history: RunHistory) => Promise<void>;
|
||||||
accessService: IAccessService;
|
accessService: IAccessService;
|
||||||
|
};
|
||||||
|
export class Executor {
|
||||||
|
pipeline: Pipeline;
|
||||||
|
runtime!: RunHistory;
|
||||||
contextFactory: ContextFactory;
|
contextFactory: ContextFactory;
|
||||||
logger: Logger;
|
logger: Logger;
|
||||||
pipelineContext!: IContext;
|
pipelineContext!: IContext;
|
||||||
lastStatusMap!: RunnableCollection;
|
lastStatusMap!: RunnableCollection;
|
||||||
|
options: ExecutorOptions;
|
||||||
onChanged: (history: RunHistory) => void;
|
onChanged: (history: RunHistory) => void;
|
||||||
constructor(options: {
|
constructor(options: ExecutorOptions) {
|
||||||
userId: any;
|
this.options = options;
|
||||||
pipeline: Pipeline;
|
|
||||||
storage: IStorage;
|
|
||||||
onChanged: (history: RunHistory) => Promise<void>;
|
|
||||||
accessService: IAccessService;
|
|
||||||
}) {
|
|
||||||
this.pipeline = _.cloneDeep(options.pipeline);
|
this.pipeline = _.cloneDeep(options.pipeline);
|
||||||
this.onChanged = async (history: RunHistory) => {
|
this.onChanged = async (history: RunHistory) => {
|
||||||
await options.onChanged(history);
|
await options.onChanged(history);
|
||||||
};
|
};
|
||||||
this.accessService = options.accessService;
|
this.pipeline.userId = options.userId;
|
||||||
this.userId = options.userId;
|
|
||||||
this.pipeline.userId = this.userId;
|
|
||||||
this.contextFactory = new ContextFactory(options.storage);
|
this.contextFactory = new ContextFactory(options.storage);
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.pipelineContext = this.contextFactory.getContext("pipeline", this.pipeline.id);
|
this.pipelineContext = this.contextFactory.getContext("pipeline", this.pipeline.id);
|
||||||
|
@ -183,10 +182,10 @@ export class Executor {
|
||||||
|
|
||||||
const context: any = {
|
const context: any = {
|
||||||
logger: this.runtime._loggers[step.id],
|
logger: this.runtime._loggers[step.id],
|
||||||
accessService: this.accessService,
|
accessService: this.options.accessService,
|
||||||
pipelineContext: this.pipelineContext,
|
pipelineContext: this.pipelineContext,
|
||||||
lastStatus,
|
lastStatus,
|
||||||
userContext: this.contextFactory.getContext("user", this.userId),
|
userContext: this.contextFactory.getContext("user", this.options.userId),
|
||||||
http: request,
|
http: request,
|
||||||
};
|
};
|
||||||
Decorator.inject(define.autowire, instance, context);
|
Decorator.inject(define.autowire, instance, context);
|
||||||
|
|
|
@ -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 & {
|
export type Pipeline = Runnable & {
|
||||||
version?: number;
|
version?: number;
|
||||||
userId: any;
|
userId: any;
|
||||||
stages: Stage[];
|
stages: Stage[];
|
||||||
triggers: Trigger[];
|
triggers: Trigger[];
|
||||||
|
notifications: Notification[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Context = {
|
export type Context = {
|
||||||
|
|
Loading…
Reference in New Issue