mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
perf: 优化证书申请成功通知发送方式
This commit is contained in:
@@ -236,8 +236,8 @@ export function createAgent(opts: CreateAgentOptions = {}) {
|
||||
}
|
||||
const httpsProxy = opts.httpsProxy;
|
||||
if (httpsProxy) {
|
||||
process.env.HTTPS_PROXY = httpProxy;
|
||||
process.env.https_proxy = httpProxy;
|
||||
process.env.HTTPS_PROXY = httpsProxy;
|
||||
process.env.https_proxy = httpsProxy;
|
||||
logger.info('use httpsProxy:', httpsProxy);
|
||||
httpsAgent = new HttpsProxyAgent(httpsProxy, opts as any);
|
||||
merge(httpsAgent.options, opts);
|
||||
|
||||
@@ -303,6 +303,7 @@ export class Executor {
|
||||
};
|
||||
const taskCtx: TaskInstanceContext = {
|
||||
pipeline: this.pipeline,
|
||||
runtime: this.runtime,
|
||||
step,
|
||||
lastStatus,
|
||||
http,
|
||||
@@ -313,6 +314,8 @@ export class Executor {
|
||||
emailService: this.options.emailService,
|
||||
cnameProxyService: this.options.cnameProxyService,
|
||||
pluginConfigService: this.options.pluginConfigService,
|
||||
notificationService: this.options.notificationService,
|
||||
urlService: this.options.urlService,
|
||||
pipelineContext: this.pipelineContext,
|
||||
userContext: this.contextFactory.getContext("user", this.options.user.id),
|
||||
fileStore: new FileStore({
|
||||
|
||||
@@ -6,13 +6,13 @@ import * as _ from "lodash-es";
|
||||
import { IEmailService } from "../service/index.js";
|
||||
|
||||
export type NotificationBody = {
|
||||
userId: number;
|
||||
userId?: number;
|
||||
title: string;
|
||||
content: string;
|
||||
pipeline: Pipeline;
|
||||
pipelineId: number;
|
||||
pipeline?: Pipeline;
|
||||
pipelineId?: number;
|
||||
result?: HistoryResult;
|
||||
historyId: number;
|
||||
historyId?: number;
|
||||
errorMessage?: string;
|
||||
url?: string;
|
||||
};
|
||||
@@ -39,6 +39,7 @@ export type NotificationDefine = Registrable & {
|
||||
export type NotificationInstanceConfig = {
|
||||
id: number;
|
||||
type: string;
|
||||
name: string;
|
||||
userId: number;
|
||||
setting: {
|
||||
[key: string]: any;
|
||||
@@ -47,6 +48,7 @@ export type NotificationInstanceConfig = {
|
||||
|
||||
export interface INotificationService {
|
||||
getById(id: number): Promise<NotificationInstanceConfig>;
|
||||
getDefault(): Promise<NotificationInstanceConfig>;
|
||||
}
|
||||
|
||||
export interface INotification {
|
||||
@@ -97,7 +99,7 @@ export abstract class BaseNotification implements INotification {
|
||||
async onTestRequest() {
|
||||
await this.send({
|
||||
userId: 0,
|
||||
title: "【Certd】测试通知",
|
||||
title: "【Certd】测试通知,标题长度测试、测试、测试",
|
||||
content: "测试通知",
|
||||
pipeline: {
|
||||
id: 1,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { Decorator } from "../decorator/index.js";
|
||||
import * as _ from "lodash-es";
|
||||
import { notificationRegistry } from "./registry.js";
|
||||
import { NotificationContext, NotificationDefine, NotificationInputDefine } from "./api.js";
|
||||
import { NotificationBody, NotificationContext, NotificationDefine, NotificationInputDefine, NotificationInstanceConfig } from "./api.js";
|
||||
|
||||
// 提供一个唯一 key
|
||||
export const NOTIFICATION_CLASS_KEY = "pipeline:notification";
|
||||
@@ -38,7 +38,7 @@ export function NotificationInput(input?: NotificationInputDefine): PropertyDeco
|
||||
};
|
||||
}
|
||||
|
||||
export function newNotification(type: string, input: any, ctx: NotificationContext) {
|
||||
export async function newNotification(type: string, input: any, ctx: NotificationContext) {
|
||||
const register = notificationRegistry.get(type);
|
||||
if (register == null) {
|
||||
throw new Error(`notification ${type} not found`);
|
||||
@@ -52,5 +52,11 @@ export function newNotification(type: string, input: any, ctx: NotificationConte
|
||||
throw new Error("ctx is required");
|
||||
}
|
||||
plugin.setCtx(ctx);
|
||||
await plugin.onInstance();
|
||||
return plugin;
|
||||
}
|
||||
|
||||
export async function sendNotification(opts: { config: NotificationInstanceConfig; ctx: NotificationContext; body: NotificationBody }) {
|
||||
const notification = await newNotification(opts.config.type, opts.config.setting, opts.ctx);
|
||||
await notification.send(opts.body);
|
||||
}
|
||||
|
||||
@@ -2,13 +2,14 @@ import { Registrable } from "../registry/index.js";
|
||||
import { FileItem, FormItemProps, Pipeline, Runnable, Step } from "../dt/index.js";
|
||||
import { FileStore } from "../core/file-store.js";
|
||||
import { IAccessService } from "../access/index.js";
|
||||
import { ICnameProxyService, IEmailService } from "../service/index.js";
|
||||
import { CancelError, IContext, RunnableCollection } from "../core/index.js";
|
||||
import { ICnameProxyService, IEmailService, IUrlService } from "../service/index.js";
|
||||
import { CancelError, IContext, RunHistory, RunnableCollection } from "../core/index.js";
|
||||
import { HttpRequestConfig, ILogger, logger, utils } from "@certd/basic";
|
||||
import { HttpClient } from "@certd/basic";
|
||||
import dayjs from "dayjs";
|
||||
import { IPluginConfigService } from "../service/config";
|
||||
import { upperFirst } from "lodash-es";
|
||||
import { INotificationService } from "../notification";
|
||||
|
||||
export type PluginRequestHandleReq<T = any> = {
|
||||
typeName: string;
|
||||
@@ -72,6 +73,8 @@ export type TaskResult = {
|
||||
export type TaskInstanceContext = {
|
||||
//流水线定义
|
||||
pipeline: Pipeline;
|
||||
//运行时历史
|
||||
runtime: RunHistory;
|
||||
//步骤定义
|
||||
step: Step;
|
||||
//日志
|
||||
@@ -86,6 +89,10 @@ export type TaskInstanceContext = {
|
||||
cnameProxyService: ICnameProxyService;
|
||||
//插件配置服务
|
||||
pluginConfigService: IPluginConfigService;
|
||||
//通知服务
|
||||
notificationService: INotificationService;
|
||||
//url构建
|
||||
urlService: IUrlService;
|
||||
//流水线上下文
|
||||
pipelineContext: IContext;
|
||||
//用户上下文
|
||||
|
||||
Reference in New Issue
Block a user