chore: plugin管理

This commit is contained in:
xiaojunnuo
2024-10-13 01:27:08 +08:00
parent 6f8fe62087
commit ccfe72a0d9
29 changed files with 729 additions and 163 deletions

View File

@@ -1,18 +1,16 @@
import { ConcurrencyStrategy, NotificationWhen, Pipeline, ResultType, Runnable, RunStrategy, Stage, Step, Task } from "../dt/index.js";
import _ from "lodash-es";
import { RunHistory, RunnableCollection } from "./run-history.js";
import { AbstractTaskPlugin, PluginDefine, pluginRegistry, TaskInstanceContext, UserInfo } from "../plugin/index.js";
import { ContextFactory, IContext } from "./context.js";
import { IStorage } from "./storage.js";
import { logger } from "../utils/index.js";
import { createAxiosService, hashUtils, logger, utils } from "../utils/index.js";
import { Logger } from "log4js";
import { createAxiosService } from "../utils/index.js";
import { IAccessService } from "../access/index.js";
import { RegistryItem } from "../registry/index.js";
import { Decorator } from "../decorator/index.js";
import { ICnameProxyService, IEmailService } from "../service/index.js";
import { ICnameProxyService, IEmailService, IPluginConfigService } from "../service/index.js";
import { FileStore } from "./file-store.js";
import { hashUtils, utils } from "../utils/index.js";
import { cloneDeep, forEach, merge } from "lodash-es";
export type ExecutorOptions = {
pipeline: Pipeline;
@@ -21,6 +19,7 @@ export type ExecutorOptions = {
accessService: IAccessService;
emailService: IEmailService;
cnameProxyService: ICnameProxyService;
pluginConfigService: IPluginConfigService;
fileRootDir?: string;
user: UserInfo;
};
@@ -42,7 +41,7 @@ export class Executor {
onChanged: (history: RunHistory) => Promise<void>;
constructor(options: ExecutorOptions) {
this.options = options;
this.pipeline = _.cloneDeep(options.pipeline);
this.pipeline = cloneDeep(options.pipeline);
this.onChanged = async (history: RunHistory) => {
await options.onChanged(history);
};
@@ -219,7 +218,7 @@ export class Executor {
// @ts-ignore
const define: PluginDefine = plugin.define;
//从outputContext读取输入参数
const input = _.cloneDeep(step.input);
const input = cloneDeep(step.input);
Decorator.inject(define.input, instance, input, (item, key) => {
if (item.component?.name === "output-selector") {
const contextKey = input[key];
@@ -269,6 +268,7 @@ export class Executor {
accessService: this.options.accessService,
emailService: this.options.emailService,
cnameProxyService: this.options.cnameProxyService,
pluginConfigService: this.options.pluginConfigService,
pipelineContext: this.pipelineContext,
userContext: this.contextFactory.getContext("user", this.options.user.id),
fileStore: new FileStore({
@@ -290,7 +290,7 @@ export class Executor {
this.lastStatusMap.clear();
}
//输出上下文变量到output context
_.forEach(define.output, (item: any, key: any) => {
forEach(define.output, (item: any, key: any) => {
step.status!.output[key] = instance[key];
// const stepOutputKey = `step.${step.id}.${key}`;
// this.runtime.context[stepOutputKey] = instance[key];
@@ -300,7 +300,7 @@ export class Executor {
if (Object.keys(instance._result.pipelineVars).length > 0) {
// 判断 pipelineVars 有值时更新
const vars = this.pipelineContext.getObj("vars");
_.merge(vars, instance._result.pipelineVars);
merge(vars, instance._result.pipelineVars);
await this.pipelineContext.setObj("vars", vars);
}
}

View File

@@ -8,8 +8,8 @@ import { IContext, PluginRequestHandleReq, RunnableCollection } from "../core/in
import { ILogger, logger, utils } from "../utils/index.js";
import { HttpClient } from "../utils/index.js";
import dayjs from "dayjs";
import _ from "lodash-es";
import { IPluginConfigService } from "../service/config";
import { upperFirst } from "lodash-es";
export type UserInfo = {
role: "admin" | "user";
id: any;
@@ -74,7 +74,7 @@ export type TaskInstanceContext = {
//cname记录服务
cnameProxyService: ICnameProxyService;
//插件配置服务
configService: IPluginConfigService;
pluginConfigService: IPluginConfigService;
//流水线上下文
pipelineContext: IContext;
//用户上下文
@@ -172,7 +172,7 @@ export abstract class AbstractTaskPlugin implements ITaskPlugin {
let methodName = req.action;
if (!req.action.startsWith("on")) {
methodName = `on${_.upperFirst(req.action)}`;
methodName = `on${upperFirst(req.action)}`;
}
// @ts-ignore

View File

@@ -1,9 +1,9 @@
import _ from "lodash-es";
import { pluginRegistry } from "./registry.js";
import { PluginDefine, TaskInputDefine, TaskOutputDefine } from "./api.js";
import { Decorator } from "../decorator/index.js";
import { AUTOWIRE_KEY } from "../decorator/index.js";
import "reflect-metadata";
import { merge, sortBy } from "lodash-es";
// 提供一个唯一 key
export const PLUGIN_CLASS_KEY = "pipeline:plugin";
@@ -42,13 +42,13 @@ export function IsTaskPlugin(define: PluginDefine): ClassDecorator {
}
inputArray.push([key, _input]);
}
inputArray = _.sortBy(inputArray, (item: any) => item[1].order);
inputArray = sortBy(inputArray, (item: any) => item[1].order);
const inputMap: any = {};
inputArray.forEach((item: any) => {
inputMap[item[0]] = item[1];
});
_.merge(define, { input: inputMap, autowire: autowires, output: outputs });
merge(define, { input: inputMap, autowire: autowires, output: outputs });
Reflect.defineMetadata(PLUGIN_CLASS_KEY, define, target);

View File

@@ -1,9 +1,8 @@
import { FormItemProps } from "../d.ts/index.js";
export type PluginConfig = {
show: false;
sysInput: {
[key: string]: {};
name: string;
disabled: boolean;
sysSetting: {
[key: string]: any;
};
};

View File

@@ -1,2 +1,3 @@
export * from "./email.js";
export * from "./cname.js";
export * from "./config.js";