mirror of https://github.com/certd/certd
fix: 修复重试次数设置无效的bug
parent
c937583a50
commit
e2099ac9ca
|
@ -130,7 +130,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
|||
await api.DoCheck(row.id);
|
||||
await crudExpose.doRefresh();
|
||||
notification.success({
|
||||
message: "检查完成",
|
||||
message: "检查任务已提交,请稍后刷新查看结果",
|
||||
});
|
||||
},
|
||||
},
|
||||
|
|
|
@ -137,7 +137,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
|||
await api.DoCheck(row.id);
|
||||
await crudExpose.doRefresh();
|
||||
notification.success({
|
||||
message: "检查任务已提交",
|
||||
message: "检查任务已提交,请稍后刷新查看结果",
|
||||
});
|
||||
},
|
||||
},
|
||||
|
|
|
@ -104,7 +104,7 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
|||
* @param notify
|
||||
* @param retryTimes
|
||||
*/
|
||||
async doCheck(site: SiteInfoEntity, notify = true, retryTimes = 3) {
|
||||
async doCheck(site: SiteInfoEntity, notify = true, retryTimes = null) {
|
||||
if (!site?.domain) {
|
||||
throw new Error("站点域名不能为空");
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
|||
|
||||
|
||||
//检查ip
|
||||
await this.checkAllIp(site);
|
||||
await this.checkAllIp(site,retryTimes);
|
||||
|
||||
if (!notify) {
|
||||
return;
|
||||
|
@ -181,7 +181,7 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
|||
}
|
||||
}
|
||||
|
||||
async checkAllIp(site: SiteInfoEntity) {
|
||||
async checkAllIp(site: SiteInfoEntity,retryTimes = null) {
|
||||
if (!site.ipCheck) {
|
||||
return;
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
|||
logger.error("send notify error", e);
|
||||
}
|
||||
};
|
||||
await this.siteIpService.checkAll(site, onFinished);
|
||||
await this.siteIpService.checkAll(site, retryTimes,onFinished);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -234,7 +234,7 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
|||
* @param notify
|
||||
* @param retryTimes
|
||||
*/
|
||||
async check(id: number, notify = false, retryTimes = 3) {
|
||||
async check(id: number, notify = false, retryTimes = null) {
|
||||
const site = await this.info(id);
|
||||
if (!site) {
|
||||
throw new Error("站点不存在");
|
||||
|
@ -326,7 +326,6 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
|||
return setting;
|
||||
}
|
||||
for (const site of sites) {
|
||||
let retryTimes = 3;
|
||||
const setting = await getFromCache(site.userId)
|
||||
if (isCommon) {
|
||||
//公共的检查,排除有设置cron的用户
|
||||
|
@ -334,8 +333,8 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
|||
//设置了cron,跳过公共检查
|
||||
continue;
|
||||
}
|
||||
retryTimes = setting.retryTimes??retryTimes
|
||||
}
|
||||
let retryTimes = setting?.retryTimes
|
||||
this.doCheck(site,true,retryTimes).catch(e => {
|
||||
logger.error(`检查站点证书失败,${site.domain}`, e.message);
|
||||
});
|
||||
|
|
|
@ -88,7 +88,7 @@ export class SiteIpService extends BaseService<SiteIpEntity> {
|
|||
await this.updateIpCount(entity.id)
|
||||
}
|
||||
|
||||
async check(ipId: number, domain: string, port: number) {
|
||||
async check(ipId: number, domain: string, port: number,retryTimes = null) {
|
||||
if(!ipId){
|
||||
return
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ export class SiteIpService extends BaseService<SiteIpEntity> {
|
|||
const res = await siteTester.test({
|
||||
host: domain,
|
||||
port: port,
|
||||
retryTimes: 3,
|
||||
retryTimes : retryTimes??3,
|
||||
ipAddress: entity.ipAddress
|
||||
});
|
||||
|
||||
|
@ -154,7 +154,7 @@ export class SiteIpService extends BaseService<SiteIpEntity> {
|
|||
}
|
||||
}
|
||||
|
||||
async checkAll(siteInfo: SiteInfoEntity,onFinish?: (e: any) => void) {
|
||||
async checkAll(siteInfo: SiteInfoEntity,retryTimes = null,onFinish?: (e: any) => void) {
|
||||
const siteId = siteInfo.id;
|
||||
const ips = await this.repository.find({
|
||||
where: {
|
||||
|
@ -167,7 +167,7 @@ export class SiteIpService extends BaseService<SiteIpEntity> {
|
|||
for (const item of ips) {
|
||||
const func = async () => {
|
||||
try {
|
||||
return await this.check(item.id, domain, port);
|
||||
return await this.check(item.id, domain, port,retryTimes);
|
||||
} catch (e) {
|
||||
logger.error("check site item error", e);
|
||||
return {
|
||||
|
|
|
@ -18,7 +18,7 @@ export type SiteTestRes = {
|
|||
export class SiteTester {
|
||||
async test(req: SiteTestReq): Promise<SiteTestRes> {
|
||||
logger.info("测试站点:", JSON.stringify(req));
|
||||
const maxRetryTimes = req.retryTimes ?? 3;
|
||||
const maxRetryTimes = req.retryTimes==null ? 3 : req.retryTimes;
|
||||
let tryCount = 0;
|
||||
let result: SiteTestRes = {};
|
||||
while (true) {
|
||||
|
@ -28,12 +28,12 @@ export class SiteTester {
|
|||
} catch (e) {
|
||||
tryCount++;
|
||||
if (tryCount > maxRetryTimes) {
|
||||
logger.error(`测试站点出错,重试${maxRetryTimes}次。`, e.message);
|
||||
logger.error(`测试站点出错,已超过最大重试次数(${maxRetryTimes})`, e.message);
|
||||
throw e;
|
||||
}
|
||||
//指数退避
|
||||
const time = 2 ** tryCount;
|
||||
logger.error(`测试站点出错,${time}s后重试`, e);
|
||||
logger.error(`测试站点出错,${time}s后重试(${tryCount}/${maxRetryTimes})`, e);
|
||||
await utils.sleep(time * 1000);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,8 @@ export class TelegramNotification extends BaseNotification {
|
|||
skipSslVerify: boolean;
|
||||
|
||||
replaceText(text: string) {
|
||||
return text.replaceAll('.', '\\.').replaceAll('*', '\\*');
|
||||
// .*()<> 等都需要用\\进行替换
|
||||
return text.replace(/[\\.*()<>]/g, '\\$&');
|
||||
}
|
||||
async send(body: NotificationBody) {
|
||||
if (!this.botToken || !this.chatId) {
|
||||
|
|
Loading…
Reference in New Issue