fix: 修复腾讯clb重复执行会报错的bug

pull/330/head
xiaojunnuo 2025-01-20 11:53:52 +08:00
parent c20bb38b06
commit e95d29f446
1 changed files with 26 additions and 23 deletions

View File

@ -135,32 +135,35 @@ export class DeployCertToTencentCLB extends AbstractTaskPlugin {
const domains = Array.isArray(this.domain) ? this.domain : [this.domain]; const domains = Array.isArray(this.domain) ? this.domain : [this.domain];
for (const domain of domains) { for (const domain of domains) {
this.logger.info(`开始更新域名证书:${domain},请确保已经开启了sni`); this.logger.info(`开始更新域名证书:${domain},请确保已经开启了sni`);
const lastCertId = await this.getCertIdFromProps(client, domain); // const lastCertId = await this.getCertIdFromProps(client, domain);
await this.updateByDomainAttr(client, domain); await this.updateByDomainAttr(client, domain);
const checkDeployed = async (wait = 5) => { this.logger.info(`设置腾讯云CLB证书(sni)成功:loadBalancerId:${this.loadBalancerId},listenerId:${this.listenerId},domain:${domain}`);
await this.ctx.utils.sleep(wait * 1000);
this.logger.info(`等待${wait}`); // 不要做检查相同的证书不会生成新的证书id
const newCertId = await this.getCertIdFromProps(client, domain); // const checkDeployed = async (wait = 5) => {
this.logger.info(`oldCertId:${lastCertId} , newCertId:${newCertId}`); // await this.ctx.utils.sleep(wait * 1000);
if ((lastCertId && newCertId === lastCertId) || (!lastCertId && !newCertId)) { // this.logger.info(`等待${wait}秒`);
return false; // const newCertId = await this.getCertIdFromProps(client, domain);
} // this.logger.info(`oldCertId:${lastCertId} , newCertId:${newCertId}`);
this.logger.info('腾讯云证书ID:', newCertId); // if ((lastCertId && newCertId === lastCertId) || (!lastCertId && !newCertId)) {
return true; // return false;
}; // }
let count = 0; // this.logger.info('腾讯云证书ID:', newCertId);
while (true) { // return true;
count++; // };
const res = await checkDeployed(5); // let count = 0;
if (res) { // while (true) {
break; // count++;
} // const res = await checkDeployed(5);
if (count > 6) { // if (res) {
throw new Error('部署可能失败请确认是否已开启sni'); // break;
} // }
} // if (count > 6) {
// this.logger.warn('等待超时,可能证书未部署成功');
// }
// }
} }
} }