refactor: fix bugs

pull/9/head^2
xiaojunnuo 2022-10-31 15:01:50 +08:00
parent 146ac49703
commit 6094a4af79
7 changed files with 41 additions and 16 deletions

View File

@ -28,9 +28,10 @@ export class Executor {
this.pipelineContext = this.contextFactory.getContext("pipeline", this.pipeline.id); this.pipelineContext = this.contextFactory.getContext("pipeline", this.pipeline.id);
} }
async run(runtimeId: any = 0) { async run(runtimeId: any = 0, triggerType: string) {
try { try {
this.runtime = new RunHistory(runtimeId, this.pipeline); const trigger = { type: triggerType };
this.runtime = new RunHistory(runtimeId, trigger, this.pipeline);
this.logger.info(`pipeline.${this.pipeline.id} start`); this.logger.info(`pipeline.${this.pipeline.id} start`);
await this.runWithHistory(this.pipeline, "pipeline", async () => { await this.runWithHistory(this.pipeline, "pipeline", async () => {
await this.runStages(); await this.runStages();
@ -62,7 +63,6 @@ export class Executor {
await this.onChanged(this.runtime); await this.onChanged(this.runtime);
return ResultType.success; return ResultType.success;
} catch (e: any) { } catch (e: any) {
this.logger.error(e);
this.runtime.error(runnable, e); this.runtime.error(runnable, e);
await this.pipelineContext.set(contextKey, ResultType.error); await this.pipelineContext.set(contextKey, ResultType.error);
await this.onChanged(this.runtime); await this.onChanged(this.runtime);
@ -140,7 +140,7 @@ export class Executor {
const define = taskPlugin.getDefine(); const define = taskPlugin.getDefine();
//从outputContext读取输入参数 //从outputContext读取输入参数
_.forEach(define.input, (item, key) => { _.forEach(define.input, (item, key) => {
if (item.component?.name === "output-selector") { if (item.component?.name === "pi-output-selector") {
const contextKey = step.input[key]; const contextKey = step.input[key];
if (contextKey != null) { if (contextKey != null) {
step.input[key] = this.runtime.context[contextKey]; step.input[key] = this.runtime.context[contextKey];

View File

@ -8,6 +8,9 @@ export type HistoryStatus = {
logs: string[]; logs: string[];
}; };
export type RunTrigger = {
type: string; // user , timer
};
export class RunHistory { export class RunHistory {
id: string; id: string;
//运行时上下文变量 //运行时上下文变量
@ -19,9 +22,11 @@ export class RunHistory {
loggers: { loggers: {
[runnableId: string]: Logger; [runnableId: string]: Logger;
} = {}; } = {};
constructor(runtimeId: any, pipeline: Pipeline) { trigger: RunTrigger;
constructor(runtimeId: any, trigger: RunTrigger, pipeline: Pipeline) {
this.id = runtimeId; this.id = runtimeId;
this.pipeline = pipeline; this.pipeline = pipeline;
this.trigger = trigger;
} }
start(runnable: Runnable): HistoryResult { start(runnable: Runnable): HistoryResult {
@ -72,7 +77,7 @@ export class RunHistory {
message: e.message, message: e.message,
}); });
this.log(runnable, `执行异常:${e.message}`); this.logError(runnable, e);
} }
log(runnable: Runnable, text: string) { log(runnable: Runnable, text: string) {
@ -80,6 +85,11 @@ export class RunHistory {
this.loggers[runnable.id].info(`[${runnable.title}]<id:${runnable.id}> [${runnable.runnableType}]`, text); this.loggers[runnable.id].info(`[${runnable.title}]<id:${runnable.id}> [${runnable.runnableType}]`, text);
} }
logError(runnable: Runnable, e: Error) {
// @ts-ignore
this.loggers[runnable.id].error(`[${runnable.title}]<id:${runnable.id}> [${runnable.runnableType}]`, e);
}
finally(runnable: Runnable) { finally(runnable: Runnable) {
// //
} }

View File

@ -52,6 +52,7 @@ export type Trigger = {
id: string; id: string;
title: string; title: string;
cron: string; cron: string;
type: string;
}; };
export type Runnable = { export type Runnable = {
@ -60,6 +61,9 @@ export type Runnable = {
strategy?: RunnableStrategy; strategy?: RunnableStrategy;
runnableType?: string; // pipeline, stage, task , step runnableType?: string; // pipeline, stage, task , step
status?: HistoryResult; status?: HistoryResult;
default?: {
[key: string]: any;
};
}; };
export type Pipeline = Runnable & { export type Pipeline = Runnable & {

View File

@ -23,6 +23,7 @@ export type CertInfo = {
vModel: "value", vModel: "value",
mode: "tags", mode: "tags",
}, },
required: true,
col: { col: {
span: 24, span: 24,
}, },
@ -34,6 +35,7 @@ export type CertInfo = {
name: "a-input", name: "a-input",
vModel: "value", vModel: "value",
}, },
required: true,
helper: "请输入邮箱", helper: "请输入邮箱",
}, },
dnsProviderType: { dnsProviderType: {
@ -41,6 +43,7 @@ export type CertInfo = {
component: { component: {
name: "pi-dns-provider-selector", name: "pi-dns-provider-selector",
}, },
required: true,
helper: "请选择dns解析提供商", helper: "请选择dns解析提供商",
}, },
dnsProviderAccess: { dnsProviderAccess: {
@ -48,20 +51,20 @@ export type CertInfo = {
component: { component: {
name: "pi-access-selector", name: "pi-access-selector",
}, },
required: true,
helper: "请选择dns解析提供商授权", helper: "请选择dns解析提供商授权",
}, },
renewDays: { renewDays: {
title: "更新天数", title: "更新天数",
value: 20,
component: { component: {
name: "a-input-number", name: "a-input-number",
vModel: "value", vModel: "value",
}, },
required: true,
helper: "到期前多少天后更新证书", helper: "到期前多少天后更新证书",
}, },
forceUpdate: { forceUpdate: {
title: "强制更新", title: "强制更新",
value: false,
component: { component: {
name: "a-switch", name: "a-switch",
vModel: "checked", vModel: "checked",
@ -69,6 +72,12 @@ export type CertInfo = {
helper: "是否强制重新申请证书", helper: "是否强制重新申请证书",
}, },
}, },
default: {
input: {
renewDays: 20,
forceUpdate: false,
},
},
output: { output: {
cert: { cert: {
key: "cert", key: "cert",

View File

@ -5,6 +5,7 @@ import Core from "@alicloud/pop-core";
import RPCClient from "@alicloud/pop-core"; import RPCClient from "@alicloud/pop-core";
import { AliyunAccess } from "../../../access"; import { AliyunAccess } from "../../../access";
import { CertInfo } from "../cert-plugin"; import { CertInfo } from "../cert-plugin";
import { RunStrategy } from "../../../d.ts";
@IsTask(() => { @IsTask(() => {
return { return {
@ -14,16 +15,12 @@ import { CertInfo } from "../cert-plugin";
input: { input: {
domainName: { domainName: {
title: "CDN加速域名", title: "CDN加速域名",
component: { helper: "你在阿里云上配置的CDN加速域名比如certd.docmirror.cn",
placeholder: "你在阿里云上配置的CDN加速域名比如certd.docmirror.cn",
},
required: true, required: true,
}, },
certName: { certName: {
title: "证书名称", title: "证书名称",
component: { helper: "上传后将以此名称作为前缀备注",
placeholder: "上传后将以此名称作为前缀备注",
},
}, },
cert: { cert: {
title: "域名证书", title: "域名证书",
@ -44,6 +41,11 @@ import { CertInfo } from "../cert-plugin";
}, },
}, },
output: {}, output: {},
default: {
strategy: {
runStrategy: RunStrategy.SkipWhenSucceed,
},
},
}; };
}) })
export class DeployCertToAliyunCDN extends AbstractPlugin implements TaskPlugin { export class DeployCertToAliyunCDN extends AbstractPlugin implements TaskPlugin {

View File

@ -2,7 +2,7 @@ import log4js, { LoggingEvent } from "log4js";
const OutputAppender = { const OutputAppender = {
configure: (config: any, layouts: any, findAppender: any, levels: any) => { configure: (config: any, layouts: any, findAppender: any, levels: any) => {
let layout = layouts.colouredLayout; let layout = layouts.basicLayout;
if (config.layout) { if (config.layout) {
layout = layouts.layout(config.layout.type, config.layout); layout = layouts.layout(config.layout.type, config.layout);
} }

View File

@ -12,7 +12,7 @@ describe("pipeline", function () {
} }
const executor = new Executor({ userId: "test", pipeline, onChanged, accessService: new AccessServiceTest(), storage: new FileStorage() }); const executor = new Executor({ userId: "test", pipeline, onChanged, accessService: new AccessServiceTest(), storage: new FileStorage() });
await executor.run(); await executor.run(1, "user");
// expect(define.name).eq("EchoPlugin"); // expect(define.name).eq("EchoPlugin");
}); });
}); });