@certd/pipeline 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/bundle.js +8 -0
- package/dist/d/access/api.d.ts +16 -0
- package/dist/d/access/decorator.d.ts +5 -0
- package/{src/plugin/index.ts → dist/d/access/index.d.ts} +3 -3
- package/dist/d/access/registry.d.ts +2 -0
- package/{src/context/index.ts → dist/d/context/index.d.ts} +5 -6
- package/dist/d/core/context.d.ts +32 -0
- package/dist/d/core/executor.d.ts +32 -0
- package/{src/core/index.ts → dist/d/core/index.d.ts} +4 -4
- package/dist/d/core/run-history.d.ts +39 -0
- package/dist/d/core/storage.d.ts +30 -0
- package/dist/d/d.ts/fast-crud.d.ts +107 -0
- package/{src/d.ts/index.ts → dist/d/d.ts/index.d.ts} +2 -2
- package/dist/d/d.ts/pipeline.d.ts +103 -0
- package/dist/d/decorator/common.d.ts +6 -0
- package/{src/decorator/index.ts → dist/d/decorator/index.d.ts} +2 -2
- package/dist/d/decorator/utils.d.ts +11 -0
- package/{src/index.ts → dist/d/index.d.ts} +9 -9
- package/dist/d/midway/configuration.d.ts +8 -0
- package/dist/d/midway/index.d.ts +1 -0
- package/dist/d/plugin/api.d.ts +48 -0
- package/dist/d/plugin/decorator.d.ts +7 -0
- package/{src/access/index.ts → dist/d/plugin/index.d.ts} +3 -3
- package/{src/plugin/registry.ts → dist/d/plugin/registry.d.ts} +3 -4
- package/dist/d/plugin/test/echo-plugin.d.ts +8 -0
- package/{src/registry/index.ts → dist/d/registry/index.d.ts} +1 -1
- package/dist/d/registry/registry.d.ts +26 -0
- package/dist/d/utils/index.d.ts +6 -0
- package/dist/d/utils/util.log.d.ts +4 -0
- package/dist/d/utils/util.request.d.ts +1 -0
- package/dist/d/utils/util.sleep.d.ts +1 -0
- package/dist/pipeline.mjs +11 -0
- package/dist/pipeline.umd.js +1 -0
- package/package.json +34 -37
- package/rollup.config.js +39 -0
- package/test/echo-plugin.ts +1 -4
- package/tsconfig.json +7 -4
- package/vite.config.js +30 -6
- package/src/access/api.ts +0 -18
- package/src/access/decorator.ts +0 -39
- package/src/access/registry.ts +0 -4
- package/src/core/context.ts +0 -88
- package/src/core/executor.ts +0 -207
- package/src/core/run-history.ts +0 -158
- package/src/core/storage.ts +0 -140
- package/src/d.ts/fast-crud.ts +0 -115
- package/src/d.ts/pipeline.ts +0 -119
- package/src/decorator/common.ts +0 -17
- package/src/decorator/utils.ts +0 -42
- package/src/midway/configuration.ts +0 -52
- package/src/midway/index.ts +0 -5
- package/src/plugin/api.ts +0 -60
- package/src/plugin/decorator.ts +0 -63
- package/src/plugin/test/echo-plugin.ts +0 -31
- package/src/registry/registry.ts +0 -57
- package/src/utils/index.ts +0 -7
- package/src/utils/util.log.ts +0 -35
- package/src/utils/util.request.ts +0 -58
- package/src/utils/util.sleep.ts +0 -7
package/package.json
CHANGED
|
@@ -1,56 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@certd/pipeline",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0.
|
|
5
|
-
"main": "./dist/
|
|
4
|
+
"version": "1.0.3",
|
|
5
|
+
"main": "./dist/bundle.js",
|
|
6
6
|
"module": "./dist/pipeline.mjs",
|
|
7
7
|
"types": "./dist/d/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"dev": "vite",
|
|
10
|
-
"build": "
|
|
10
|
+
"build": "rollup -c",
|
|
11
|
+
"build2": "vue-tsc --noEmit && vite build",
|
|
11
12
|
"preview": "vite preview"
|
|
12
13
|
},
|
|
13
14
|
"dependencies": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"lodash": "^4.17.21",
|
|
18
|
-
"log4js": "^6.3.0",
|
|
19
|
-
"node-forge": "^0.10.0",
|
|
20
|
-
"qs": "^6.9.4",
|
|
21
|
-
"reflect-metadata": "^0.1.13"
|
|
15
|
+
"axios": "^1.4.0",
|
|
16
|
+
"node-forge": "^1.3.1",
|
|
17
|
+
"qs": "^6.11.2"
|
|
22
18
|
},
|
|
23
19
|
"devDependencies": {
|
|
24
|
-
"@
|
|
25
|
-
"@
|
|
26
|
-
"@
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
29
|
-
"@midwayjs/cli": "^1.3.21",
|
|
30
|
-
"@midwayjs/core": "^3.0.0",
|
|
31
|
-
"@midwayjs/decorator": "^3.0.0",
|
|
32
|
-
"@midwayjs/koa": "^3.9.0",
|
|
33
|
-
"@midwayjs/logger": "^2.17.0",
|
|
34
|
-
"@midwayjs/typeorm": "^3.9.0",
|
|
35
|
-
"@midwayjs/validate": "^3.9.0",
|
|
20
|
+
"@certd/acme-client": "^1.0.3",
|
|
21
|
+
"@rollup/plugin-commonjs": "^23.0.4",
|
|
22
|
+
"@rollup/plugin-json": "^6.0.0",
|
|
23
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
24
|
+
"@rollup/plugin-terser": "^0.4.3",
|
|
36
25
|
"@rollup/plugin-typescript": "^11.0.0",
|
|
37
|
-
"@types/chai": "^4.3.
|
|
26
|
+
"@types/chai": "^4.3.5",
|
|
38
27
|
"@types/lodash": "^4.14.194",
|
|
39
|
-
"@types/mocha": "^10.0.
|
|
40
|
-
"@types/node-forge": "^1.3.
|
|
41
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
42
|
-
"@typescript-eslint/parser": "^5.
|
|
43
|
-
"chai": "^4.3.
|
|
44
|
-
"
|
|
45
|
-
"eslint
|
|
46
|
-
"eslint-
|
|
28
|
+
"@types/mocha": "^10.0.1",
|
|
29
|
+
"@types/node-forge": "^1.3.2",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^5.59.7",
|
|
31
|
+
"@typescript-eslint/parser": "^5.59.7",
|
|
32
|
+
"chai": "^4.3.7",
|
|
33
|
+
"dayjs": "^1.11.7",
|
|
34
|
+
"eslint": "^8.41.0",
|
|
35
|
+
"eslint-config-prettier": "^8.8.0",
|
|
36
|
+
"eslint-plugin-import": "^2.27.5",
|
|
47
37
|
"eslint-plugin-node": "^11.1.0",
|
|
48
38
|
"eslint-plugin-prettier": "^4.2.1",
|
|
49
|
-
"
|
|
39
|
+
"lodash": "^4.17.21",
|
|
40
|
+
"log4js": "^6.9.1",
|
|
41
|
+
"mocha": "^10.2.0",
|
|
42
|
+
"reflect-metadata": "^0.1.13",
|
|
43
|
+
"rollup": "^3.7.4",
|
|
44
|
+
"rollup-plugin-typescript2": "^0.34.1",
|
|
45
|
+
"rollup-plugin-visualizer": "^5.8.2",
|
|
50
46
|
"ts-node": "^10.9.1",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
47
|
+
"tslib": "^2.5.2",
|
|
48
|
+
"typescript": "^5.0.4",
|
|
49
|
+
"vite": "^4.3.8",
|
|
50
|
+
"vue-tsc": "^1.6.5"
|
|
54
51
|
},
|
|
55
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "a43c5b0824d2cb19a731c16f62c5e7464f6635d6"
|
|
56
53
|
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const resolve = require("@rollup/plugin-node-resolve");
|
|
2
|
+
const commonjs = require("@rollup/plugin-commonjs");
|
|
3
|
+
const rollupTypescript = require("rollup-plugin-typescript2");
|
|
4
|
+
const json = require("@rollup/plugin-json");
|
|
5
|
+
const terser = require("@rollup/plugin-terser");
|
|
6
|
+
module.exports = {
|
|
7
|
+
input: "src/index.ts",
|
|
8
|
+
output: {
|
|
9
|
+
file: "dist/bundle.js",
|
|
10
|
+
format: "cjs",
|
|
11
|
+
},
|
|
12
|
+
plugins: [
|
|
13
|
+
// 解析第三方依赖
|
|
14
|
+
resolve(),
|
|
15
|
+
// 识别 commonjs 模式第三方依赖
|
|
16
|
+
commonjs(),
|
|
17
|
+
rollupTypescript(),
|
|
18
|
+
json(),
|
|
19
|
+
terser(),
|
|
20
|
+
],
|
|
21
|
+
external: [
|
|
22
|
+
"vue",
|
|
23
|
+
"lodash",
|
|
24
|
+
"dayjs",
|
|
25
|
+
"@certd/acme-client",
|
|
26
|
+
"@certd/pipeline",
|
|
27
|
+
"@certd/plugin-cert",
|
|
28
|
+
"@certd/plugin-aliyun",
|
|
29
|
+
"@certd/plugin-tencent",
|
|
30
|
+
"@certd/plugin-huawei",
|
|
31
|
+
"@certd/plugin-host",
|
|
32
|
+
"@certd/plugin-tencent",
|
|
33
|
+
"@certd/plugin-util",
|
|
34
|
+
"log4js",
|
|
35
|
+
"@midwayjs/core",
|
|
36
|
+
"@midwayjs/decorator",
|
|
37
|
+
"reflect-metadata",
|
|
38
|
+
],
|
|
39
|
+
};
|
package/test/echo-plugin.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Autowire,
|
|
1
|
+
import { Autowire, IsTaskPlugin, ITaskPlugin, TaskInput, TaskOutput } from "../src";
|
|
2
2
|
|
|
3
3
|
@IsTaskPlugin({
|
|
4
4
|
name: "EchoPlugin",
|
|
@@ -14,9 +14,6 @@ export class EchoPlugin implements ITaskPlugin {
|
|
|
14
14
|
})
|
|
15
15
|
cert!: any;
|
|
16
16
|
|
|
17
|
-
@Autowire()
|
|
18
|
-
logger!: ILogger;
|
|
19
|
-
|
|
20
17
|
@TaskOutput({
|
|
21
18
|
title: "cert info",
|
|
22
19
|
})
|
package/tsconfig.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
+
"importHelpers": false,
|
|
3
4
|
"target": "ESNext",
|
|
4
5
|
"useDefineForClassFields": true,
|
|
5
|
-
"module": "
|
|
6
|
+
"module": "ESNext",
|
|
6
7
|
"moduleResolution": "Node",
|
|
7
8
|
"strict": true,
|
|
8
9
|
"jsx": "preserve",
|
|
@@ -13,8 +14,10 @@
|
|
|
13
14
|
"lib": ["ESNext", "DOM"],
|
|
14
15
|
"skipLibCheck": true,
|
|
15
16
|
"experimentalDecorators": true,
|
|
16
|
-
"
|
|
17
|
-
|
|
17
|
+
"paths": {
|
|
18
|
+
"tslib" : ["./node_modules/tslib/tslib.d.ts"]
|
|
19
|
+
}
|
|
18
20
|
},
|
|
19
|
-
|
|
21
|
+
|
|
22
|
+
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue","test/**/*.ts","rollup.config.ts"],
|
|
20
23
|
}
|
package/vite.config.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { defineConfig } from "vite";
|
|
2
|
+
import visualizer from "rollup-plugin-visualizer";
|
|
2
3
|
import typescript from "@rollup/plugin-typescript";
|
|
3
4
|
// https://vitejs.dev/config/
|
|
4
5
|
export default defineConfig({
|
|
5
6
|
plugins: [],
|
|
6
7
|
build: {
|
|
8
|
+
target: "es2015",
|
|
7
9
|
lib: {
|
|
8
10
|
entry: "src/index.ts",
|
|
9
|
-
name: "
|
|
11
|
+
name: "CertdPipeline",
|
|
10
12
|
},
|
|
11
13
|
rollupOptions: {
|
|
12
14
|
plugins: [
|
|
15
|
+
visualizer(),
|
|
13
16
|
typescript({
|
|
14
|
-
target: "
|
|
17
|
+
target: "es2015",
|
|
15
18
|
rootDir: "src",
|
|
16
19
|
declaration: true,
|
|
17
20
|
declarationDir: "dist/d",
|
|
@@ -19,15 +22,36 @@ export default defineConfig({
|
|
|
19
22
|
allowSyntheticDefaultImports: true,
|
|
20
23
|
}),
|
|
21
24
|
],
|
|
22
|
-
external: [
|
|
25
|
+
external: [
|
|
26
|
+
"vue",
|
|
27
|
+
"lodash",
|
|
28
|
+
"dayjs",
|
|
29
|
+
"@certd/acme-client",
|
|
30
|
+
"@certd/plugin-cert",
|
|
31
|
+
"@certd/plugin-aliyun",
|
|
32
|
+
"@certd/plugin-tencent",
|
|
33
|
+
"@certd/plugin-huawei",
|
|
34
|
+
"@certd/plugin-host",
|
|
35
|
+
"@certd/plugin-tencent",
|
|
36
|
+
"@certd/plugin-util",
|
|
37
|
+
"log4js",
|
|
38
|
+
"@midwayjs/core",
|
|
39
|
+
"@midwayjs/decorator",
|
|
40
|
+
],
|
|
23
41
|
output: {
|
|
24
|
-
// Provide global variables to use in the UMD build
|
|
25
|
-
// for externalized deps
|
|
26
42
|
globals: {
|
|
27
43
|
vue: "Vue",
|
|
28
44
|
lodash: "_",
|
|
29
45
|
dayjs: "dayjs",
|
|
30
|
-
"@
|
|
46
|
+
"@certd/plugin-cert": "CertdPluginCert",
|
|
47
|
+
"@certd/acme-client": "CertdAcmeClient",
|
|
48
|
+
"@certd/plugin-aliyun": "CertdPluginAliyun",
|
|
49
|
+
"@certd/plugin-host": "CertdPluginHost",
|
|
50
|
+
"@certd/plugin-huawei": "CertdPluginHuawei",
|
|
51
|
+
"@certd/plugin-util": "CertdPluginUtil",
|
|
52
|
+
log4js: "log4js",
|
|
53
|
+
"@midwayjs/core": "MidwayjsCore",
|
|
54
|
+
"@midwayjs/decorator": "MidwayjsDecorator",
|
|
31
55
|
},
|
|
32
56
|
},
|
|
33
57
|
},
|
package/src/access/api.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Registrable } from "../registry";
|
|
2
|
-
import { FormItemProps } from "../d.ts";
|
|
3
|
-
|
|
4
|
-
export type AccessInputDefine = FormItemProps & {
|
|
5
|
-
title: string;
|
|
6
|
-
required?: boolean;
|
|
7
|
-
};
|
|
8
|
-
export type AccessDefine = Registrable & {
|
|
9
|
-
input?: {
|
|
10
|
-
[key: string]: AccessInputDefine;
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
export interface IAccessService {
|
|
14
|
-
getById(id: any): Promise<any>;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
18
|
-
export interface IAccess {}
|
package/src/access/decorator.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// src/decorator/memoryCache.decorator.ts
|
|
2
|
-
import { AccessDefine, AccessInputDefine } from "./api";
|
|
3
|
-
import { Decorator } from "../decorator";
|
|
4
|
-
import _ from "lodash";
|
|
5
|
-
import { accessRegistry } from "./registry";
|
|
6
|
-
|
|
7
|
-
// 提供一个唯一 key
|
|
8
|
-
export const ACCESS_CLASS_KEY = "pipeline:access";
|
|
9
|
-
export const ACCESS_INPUT_KEY = "pipeline:access:input";
|
|
10
|
-
|
|
11
|
-
export function IsAccess(define: AccessDefine): ClassDecorator {
|
|
12
|
-
return (target: any) => {
|
|
13
|
-
target = Decorator.target(target);
|
|
14
|
-
|
|
15
|
-
const inputs: any = {};
|
|
16
|
-
const properties = Decorator.getClassProperties(target);
|
|
17
|
-
for (const property in properties) {
|
|
18
|
-
const input = Reflect.getMetadata(ACCESS_INPUT_KEY, target, property);
|
|
19
|
-
if (input) {
|
|
20
|
-
inputs[property] = input;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
_.merge(define, { input: inputs });
|
|
24
|
-
Reflect.defineMetadata(ACCESS_CLASS_KEY, define, target);
|
|
25
|
-
target.define = define;
|
|
26
|
-
accessRegistry.register(define.name, {
|
|
27
|
-
define,
|
|
28
|
-
target,
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function AccessInput(input?: AccessInputDefine): PropertyDecorator {
|
|
34
|
-
return (target, propertyKey) => {
|
|
35
|
-
target = Decorator.target(target, propertyKey);
|
|
36
|
-
// const _type = Reflect.getMetadata("design:type", target, propertyKey);
|
|
37
|
-
Reflect.defineMetadata(ACCESS_INPUT_KEY, input, target, propertyKey);
|
|
38
|
-
};
|
|
39
|
-
}
|
package/src/access/registry.ts
DELETED
package/src/core/context.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { IStorage, MemoryStorage } from "./storage";
|
|
2
|
-
const CONTEXT_VERSION_KEY = "contextVersion";
|
|
3
|
-
export interface IContext {
|
|
4
|
-
getInt(key: string): Promise<number>;
|
|
5
|
-
get(key: string): Promise<string | null>;
|
|
6
|
-
set(key: string, value: string): Promise<void>;
|
|
7
|
-
getObj<T = any>(key: string): Promise<T | null>;
|
|
8
|
-
setObj<T = any>(key: string, value: T): Promise<void>;
|
|
9
|
-
updateVersion(): Promise<void>;
|
|
10
|
-
initVersion(): Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class ContextFactory {
|
|
14
|
-
storage: IStorage;
|
|
15
|
-
memoryStorage: IStorage;
|
|
16
|
-
|
|
17
|
-
constructor(storage: IStorage) {
|
|
18
|
-
this.storage = storage;
|
|
19
|
-
this.memoryStorage = new MemoryStorage();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
getContext(scope: string, namespace: string): IContext {
|
|
23
|
-
const context = new StorageContext(scope, namespace, this.storage);
|
|
24
|
-
return context;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
getMemoryContext(scope: string, namespace: string): IContext {
|
|
28
|
-
const context = new StorageContext(scope, namespace, this.memoryStorage);
|
|
29
|
-
return context;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export class StorageContext implements IContext {
|
|
34
|
-
storage: IStorage;
|
|
35
|
-
namespace: string;
|
|
36
|
-
scope: string;
|
|
37
|
-
|
|
38
|
-
_version = 0;
|
|
39
|
-
_initialVersion = 0;
|
|
40
|
-
constructor(scope: string, namespace: string, storage: IStorage) {
|
|
41
|
-
this.storage = storage;
|
|
42
|
-
this.scope = scope;
|
|
43
|
-
this.namespace = namespace;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async initVersion() {
|
|
47
|
-
const version = await this.getInt(CONTEXT_VERSION_KEY);
|
|
48
|
-
this._initialVersion = version;
|
|
49
|
-
this._version = version;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async updateVersion() {
|
|
53
|
-
if (this._version === this._initialVersion) {
|
|
54
|
-
this._version++;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
await this.set(CONTEXT_VERSION_KEY, this._version.toString());
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async get(key: string) {
|
|
61
|
-
const version = key === CONTEXT_VERSION_KEY ? 0 : this._version;
|
|
62
|
-
return await this.storage.get(this.scope, this.namespace, version.toString(), key);
|
|
63
|
-
}
|
|
64
|
-
async set(key: string, value: string) {
|
|
65
|
-
const version = key === CONTEXT_VERSION_KEY ? 0 : this._version;
|
|
66
|
-
return await this.storage.set(this.scope, this.namespace, version.toString(), key, value);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async getInt(key: string): Promise<number> {
|
|
70
|
-
const str = await this.get(key);
|
|
71
|
-
if (str) {
|
|
72
|
-
return parseInt(str);
|
|
73
|
-
}
|
|
74
|
-
return 0;
|
|
75
|
-
}
|
|
76
|
-
async getObj<T = any>(key: string): Promise<T | null> {
|
|
77
|
-
const str = await this.get(key);
|
|
78
|
-
if (str) {
|
|
79
|
-
const store = JSON.parse(str);
|
|
80
|
-
return store.value;
|
|
81
|
-
}
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async setObj<T = any>(key: string, value: T) {
|
|
86
|
-
await this.set(key, JSON.stringify({ value }));
|
|
87
|
-
}
|
|
88
|
-
}
|
package/src/core/executor.ts
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { ConcurrencyStrategy, Pipeline, ResultType, Runnable, RunStrategy, Stage, Step, Task } from "../d.ts";
|
|
2
|
-
import _ from "lodash";
|
|
3
|
-
import { RunHistory, RunnableCollection } from "./run-history";
|
|
4
|
-
import { AbstractTaskPlugin, PluginDefine, pluginRegistry } from "../plugin";
|
|
5
|
-
import { ContextFactory, IContext } from "./context";
|
|
6
|
-
import { IStorage } from "./storage";
|
|
7
|
-
import { logger } from "../utils/util.log";
|
|
8
|
-
import { Logger } from "log4js";
|
|
9
|
-
import { request } from "../utils/util.request";
|
|
10
|
-
import { IAccessService } from "../access";
|
|
11
|
-
import { RegistryItem } from "../registry";
|
|
12
|
-
import { Decorator } from "../decorator";
|
|
13
|
-
|
|
14
|
-
export class Executor {
|
|
15
|
-
userId: any;
|
|
16
|
-
pipeline: Pipeline;
|
|
17
|
-
runtime!: RunHistory;
|
|
18
|
-
accessService: IAccessService;
|
|
19
|
-
contextFactory: ContextFactory;
|
|
20
|
-
logger: Logger;
|
|
21
|
-
pipelineContext!: IContext;
|
|
22
|
-
lastStatusMap!: RunnableCollection;
|
|
23
|
-
onChanged: (history: RunHistory) => void;
|
|
24
|
-
constructor(options: {
|
|
25
|
-
userId: any;
|
|
26
|
-
pipeline: Pipeline;
|
|
27
|
-
storage: IStorage;
|
|
28
|
-
onChanged: (history: RunHistory) => Promise<void>;
|
|
29
|
-
accessService: IAccessService;
|
|
30
|
-
}) {
|
|
31
|
-
this.pipeline = _.cloneDeep(options.pipeline);
|
|
32
|
-
this.onChanged = async (history: RunHistory) => {
|
|
33
|
-
await options.onChanged(history);
|
|
34
|
-
};
|
|
35
|
-
this.accessService = options.accessService;
|
|
36
|
-
this.userId = options.userId;
|
|
37
|
-
this.pipeline.userId = this.userId;
|
|
38
|
-
this.contextFactory = new ContextFactory(options.storage);
|
|
39
|
-
this.logger = logger;
|
|
40
|
-
this.pipelineContext = this.contextFactory.getContext("pipeline", this.pipeline.id);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async init() {
|
|
44
|
-
const lastRuntime = await this.pipelineContext.getObj(`lastRuntime`);
|
|
45
|
-
this.lastStatusMap = new RunnableCollection(lastRuntime?.pipeline);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async run(runtimeId: any = 0, triggerType: string) {
|
|
49
|
-
try {
|
|
50
|
-
await this.init();
|
|
51
|
-
const trigger = { type: triggerType };
|
|
52
|
-
// 读取last
|
|
53
|
-
this.runtime = new RunHistory(runtimeId, trigger, this.pipeline);
|
|
54
|
-
this.logger.info(`pipeline.${this.pipeline.id} start`);
|
|
55
|
-
await this.runWithHistory(this.pipeline, "pipeline", async () => {
|
|
56
|
-
await this.runStages(this.pipeline);
|
|
57
|
-
});
|
|
58
|
-
} catch (e) {
|
|
59
|
-
this.logger.error("pipeline 执行失败", e);
|
|
60
|
-
} finally {
|
|
61
|
-
await this.pipelineContext.setObj("lastRuntime", this.runtime);
|
|
62
|
-
this.logger.info(`pipeline.${this.pipeline.id} end`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async runWithHistory(runnable: Runnable, runnableType: string, run: () => Promise<void>) {
|
|
67
|
-
runnable.runnableType = runnableType;
|
|
68
|
-
this.runtime.start(runnable);
|
|
69
|
-
await this.onChanged(this.runtime);
|
|
70
|
-
|
|
71
|
-
if (runnable.strategy?.runStrategy === RunStrategy.SkipWhenSucceed) {
|
|
72
|
-
//如果是成功后跳过策略
|
|
73
|
-
const lastNode = this.lastStatusMap.get(runnable.id);
|
|
74
|
-
const lastResult = lastNode?.status?.status;
|
|
75
|
-
const lastInput = JSON.stringify(lastNode?.status?.input);
|
|
76
|
-
let inputChanged = false;
|
|
77
|
-
if (runnableType === "step") {
|
|
78
|
-
const step = runnable as Step;
|
|
79
|
-
const input = JSON.stringify(step.input);
|
|
80
|
-
if (input != null && lastInput !== input) {
|
|
81
|
-
//参数有变化
|
|
82
|
-
inputChanged = true;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (lastResult != null && lastResult === ResultType.success && !inputChanged) {
|
|
86
|
-
this.runtime.skip(runnable);
|
|
87
|
-
await this.onChanged(this.runtime);
|
|
88
|
-
return ResultType.skip;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
try {
|
|
92
|
-
await run();
|
|
93
|
-
this.runtime.success(runnable);
|
|
94
|
-
await this.onChanged(this.runtime);
|
|
95
|
-
return ResultType.success;
|
|
96
|
-
} catch (e: any) {
|
|
97
|
-
this.runtime.error(runnable, e);
|
|
98
|
-
await this.onChanged(this.runtime);
|
|
99
|
-
throw e;
|
|
100
|
-
} finally {
|
|
101
|
-
this.runtime.finally(runnable);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
private async runStages(pipeline: Pipeline) {
|
|
106
|
-
const resList: ResultType[] = [];
|
|
107
|
-
for (const stage of pipeline.stages) {
|
|
108
|
-
const res: ResultType = await this.runWithHistory(stage, "stage", async () => {
|
|
109
|
-
await this.runStage(stage);
|
|
110
|
-
});
|
|
111
|
-
resList.push(res);
|
|
112
|
-
}
|
|
113
|
-
return this.compositionResultType(resList);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async runStage(stage: Stage) {
|
|
117
|
-
const runnerList = [];
|
|
118
|
-
for (const task of stage.tasks) {
|
|
119
|
-
const runner = this.runWithHistory(task, "task", async () => {
|
|
120
|
-
await this.runTask(task);
|
|
121
|
-
});
|
|
122
|
-
runnerList.push(runner);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
let resList: ResultType[] = [];
|
|
126
|
-
if (stage.concurrency === ConcurrencyStrategy.Parallel) {
|
|
127
|
-
resList = await Promise.all(runnerList);
|
|
128
|
-
} else {
|
|
129
|
-
for (let i = 0; i < runnerList.length; i++) {
|
|
130
|
-
const runner = runnerList[i];
|
|
131
|
-
resList[i] = await runner;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return this.compositionResultType(resList);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
compositionResultType(resList: ResultType[]) {
|
|
138
|
-
let hasSuccess = false;
|
|
139
|
-
for (const type of resList) {
|
|
140
|
-
if (type === ResultType.error) {
|
|
141
|
-
return ResultType.error;
|
|
142
|
-
}
|
|
143
|
-
if (type === ResultType.success) {
|
|
144
|
-
hasSuccess = true;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (hasSuccess) {
|
|
148
|
-
return ResultType.success;
|
|
149
|
-
}
|
|
150
|
-
return ResultType.error;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
private async runTask(task: Task) {
|
|
154
|
-
const resList: ResultType[] = [];
|
|
155
|
-
for (const step of task.steps) {
|
|
156
|
-
step.runnableType = "step";
|
|
157
|
-
const res: ResultType = await this.runWithHistory(step, "step", async () => {
|
|
158
|
-
await this.runStep(step);
|
|
159
|
-
});
|
|
160
|
-
resList.push(res);
|
|
161
|
-
}
|
|
162
|
-
return this.compositionResultType(resList);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
private async runStep(step: Step) {
|
|
166
|
-
const lastStatus = this.lastStatusMap.get(step.id);
|
|
167
|
-
//执行任务
|
|
168
|
-
const plugin: RegistryItem<AbstractTaskPlugin> = pluginRegistry.get(step.type);
|
|
169
|
-
|
|
170
|
-
// @ts-ignore
|
|
171
|
-
const instance: ITaskPlugin = new plugin.target();
|
|
172
|
-
// @ts-ignore
|
|
173
|
-
const define: PluginDefine = plugin.define;
|
|
174
|
-
//从outputContext读取输入参数
|
|
175
|
-
Decorator.inject(define.input, instance, step.input, (item, key) => {
|
|
176
|
-
if (item.component?.name === "pi-output-selector") {
|
|
177
|
-
const contextKey = step.input[key];
|
|
178
|
-
if (contextKey != null) {
|
|
179
|
-
step.input[key] = this.runtime.context[contextKey];
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
const context: any = {
|
|
185
|
-
logger: this.runtime._loggers[step.id],
|
|
186
|
-
accessService: this.accessService,
|
|
187
|
-
pipelineContext: this.pipelineContext,
|
|
188
|
-
lastStatus,
|
|
189
|
-
userContext: this.contextFactory.getContext("user", this.userId),
|
|
190
|
-
http: request,
|
|
191
|
-
};
|
|
192
|
-
Decorator.inject(define.autowire, instance, context);
|
|
193
|
-
|
|
194
|
-
await instance.onInstance();
|
|
195
|
-
await instance.execute();
|
|
196
|
-
|
|
197
|
-
if (instance.result.clearLastStatus) {
|
|
198
|
-
this.lastStatusMap.clear();
|
|
199
|
-
}
|
|
200
|
-
//输出到output context
|
|
201
|
-
_.forEach(define.output, (item, key) => {
|
|
202
|
-
step!.status!.output[key] = instance[key];
|
|
203
|
-
const stepOutputKey = `step.${step.id}.${key}`;
|
|
204
|
-
this.runtime.context[stepOutputKey] = instance[key];
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
}
|