mirror of
https://github.com/certd/certd.git
synced 2026-05-17 05:37:30 +08:00
perf: 支持域名到期时间监控通知
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { PipelineEntity } from '../../pipeline/entity/pipeline.js';
|
||||
|
||||
@Entity('cd_job_history')
|
||||
export class JobHistoryEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column({ name: 'user_id', comment: '用户id' })
|
||||
userId: number;
|
||||
|
||||
@Column({ name: 'project_id', comment: '项目id' })
|
||||
projectId: number;
|
||||
|
||||
|
||||
@Column({ name: 'type', comment: '类型' })
|
||||
type: string;
|
||||
|
||||
@Column({ name: 'title', comment: '标题' })
|
||||
title: string;
|
||||
|
||||
@Column({ name: 'content', comment: '内容' })
|
||||
content: string;
|
||||
|
||||
@Column({ name: 'related_id', comment: '关联id' })
|
||||
relatedId: string;
|
||||
|
||||
@Column({ name: 'result', comment: '结果' })
|
||||
result: string;
|
||||
|
||||
@Column({ name: 'start_at', comment: '开始时间' })
|
||||
startAt: number;
|
||||
|
||||
@Column({ name: 'end_at', comment: '结束时间' })
|
||||
endAt: number;
|
||||
|
||||
@Column({
|
||||
name: 'create_time',
|
||||
comment: '创建时间',
|
||||
default: () => 'CURRENT_TIMESTAMP',
|
||||
})
|
||||
createTime: Date;
|
||||
|
||||
@Column({
|
||||
name: 'update_time',
|
||||
comment: '修改时间',
|
||||
default: () => 'CURRENT_TIMESTAMP',
|
||||
})
|
||||
updateTime: Date;
|
||||
|
||||
pipeline?: PipelineEntity;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { BaseService } from "@certd/lib-server";
|
||||
import { Inject, Provide, Scope, ScopeEnum } from "@midwayjs/core";
|
||||
import { InjectEntityModel } from "@midwayjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
import { UserSettingsService } from "../../mine/service/user-settings-service.js";
|
||||
import { JobHistoryEntity } from "../entity/job-history.js";
|
||||
|
||||
|
||||
@Provide()
|
||||
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
||||
export class JobHistoryService extends BaseService<JobHistoryEntity> {
|
||||
@InjectEntityModel(JobHistoryEntity)
|
||||
repository: Repository<JobHistoryEntity>;
|
||||
|
||||
|
||||
@Inject()
|
||||
userSettingsService: UserSettingsService;
|
||||
|
||||
//@ts-ignore
|
||||
getRepository() {
|
||||
return this.repository;
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,8 @@ import {SiteIpEntity} from "../entity/site-ip.js";
|
||||
import {Cron} from "../../cron/cron.js";
|
||||
import { dnsContainer } from "./dns-custom.js";
|
||||
import { merge } from "lodash-es";
|
||||
import { JobHistoryService } from "./job-history-service.js";
|
||||
import { JobHistoryEntity } from "../entity/job-history.js";
|
||||
|
||||
@Provide()
|
||||
@Scope(ScopeEnum.Request, {allowDowngrade: true})
|
||||
@@ -39,6 +41,9 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
||||
@Inject()
|
||||
siteIpService: SiteIpService;
|
||||
|
||||
@Inject()
|
||||
jobHistoryService: JobHistoryService;
|
||||
|
||||
|
||||
@Inject()
|
||||
cron: Cron;
|
||||
@@ -516,6 +521,7 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
||||
async triggerJobOnce(userId?:number,projectId?:number) {
|
||||
logger.info(`站点证书检查开始执行[${userId??'所有用户'}_${projectId??'所有项目'}]`);
|
||||
const query:any = { disabled: false };
|
||||
let jobEntity :Partial<JobHistoryEntity> = null;
|
||||
if(userId!=null){
|
||||
query.userId = userId;
|
||||
if(projectId){
|
||||
@@ -526,9 +532,19 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
||||
if (!setting.cron) {
|
||||
return;
|
||||
}
|
||||
jobEntity = {
|
||||
userId,
|
||||
projectId,
|
||||
type:"siteCertMonitor",
|
||||
title: '站点证书检查',
|
||||
result:"start",
|
||||
startAt:new Date().getTime(),
|
||||
}
|
||||
await this.jobHistoryService.add(jobEntity);
|
||||
}
|
||||
let offset = 0;
|
||||
const limit = 50;
|
||||
let count = 0;
|
||||
while (true) {
|
||||
const res = await this.page({
|
||||
query: query,
|
||||
@@ -541,10 +557,20 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
||||
}
|
||||
offset += records.length;
|
||||
const isCommon = !userId;
|
||||
count += records.length;
|
||||
await this.checkList(records,isCommon);
|
||||
}
|
||||
|
||||
logger.info(`站点证书检查完成[${userId??'所有用户'}_${projectId??'所有项目'}]`);
|
||||
if(jobEntity){
|
||||
await this.jobHistoryService.update({
|
||||
id: jobEntity.id,
|
||||
result: "done",
|
||||
content:`共检查${count}个站点`,
|
||||
endAt:new Date().getTime(),
|
||||
updateTime:new Date(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async batchDelete(ids: number[], userId: number,projectId?:number): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user