Commit 75eee2c2 authored by nanahira's avatar nanahira

enable cdn recursive

parent d4254bb4
Pipeline #783 passed with stages
in 13 minutes and 46 seconds
...@@ -66,6 +66,9 @@ class Checker { ...@@ -66,6 +66,9 @@ class Checker {
cdnRecordsRegex: RegExp[]; cdnRecordsRegex: RegExp[];
static order: number = 0; static order: number = 0;
id: number; id: number;
records: DomainRecordInfo[];
nonCDNRecords: DomainRecordInfo[];
CDNRecords: DomainRecordInfo[];
constructor(config: Config) { constructor(config: Config) {
this.config = config; this.config = config;
this.client = new Aliyun(config.aliyun); this.client = new Aliyun(config.aliyun);
...@@ -143,13 +146,19 @@ class Checker { ...@@ -143,13 +146,19 @@ class Checker {
const good = await this.checkNode(record.Value, recordInfo.port); const good = await this.checkNode(record.Value, recordInfo.port);
await this.handleRecordResult(recordInfo, good); await this.handleRecordResult(recordInfo, good);
} }
async checkCDNRecord(recordInfo: DomainRecordInfo, nonCDNRecords: DomainRecordInfo[]) { isRecordGood(recordInfo: DomainRecordInfo): boolean {
const record = recordInfo.record; if (recordInfo.isCDN) {
this.message(`Checking CDN record ${this.getRecordPattern(recordInfo)} with old status of ${record.Status}.`) const valuePrefix = this.getRecordPrefix(recordInfo.record);
const valuePrefix = this.getRecordPrefix(record); return _.any(this.records, r => {
const good = _.any(nonCDNRecords, r => { return r.record.RR === valuePrefix && this.isRecordGood(r);
return r.record.RR === valuePrefix && r.good; });
}); } else {
return recordInfo.good;
}
}
async checkCDNRecord(recordInfo: DomainRecordInfo) {
this.message(`Checking CDN record ${this.getRecordPattern(recordInfo)} with old status of ${recordInfo.record.Status}.`)
const good = this.isRecordGood(recordInfo);
this.message(`CDN Record ${this.getRecordPattern(recordInfo)} is ${good ? "good" : "bad"}.`); this.message(`CDN Record ${this.getRecordPattern(recordInfo)} is ${good ? "good" : "bad"}.`);
await this.handleRecordResult(recordInfo, good); await this.handleRecordResult(recordInfo, good);
} }
...@@ -168,15 +177,15 @@ class Checker { ...@@ -168,15 +177,15 @@ class Checker {
} }
async start() { async start() {
this.message(`Started.`); this.message(`Started.`);
const records = await this.getRecords(); this.records = await this.getRecords();
const nonCDNRecords = records.filter(m => !m.isCDN); this.nonCDNRecords = this.records.filter(m => !m.isCDN);
const CDNRecords = records.filter(m => !!m.isCDN); this.CDNRecords = this.records.filter(m => !!m.isCDN);
await Promise.all(nonCDNRecords.map(r => { await Promise.all(this.nonCDNRecords.map(r => {
return this.checkRecord(r); return this.checkRecord(r);
})); }));
//await Promise.all(CDNRecords.map(r => { await Promise.all(this.CDNRecords.map(r => {
// return this.checkCDNRecord(r, nonCDNRecords); return this.checkCDNRecord(r);
//})); }));
this.message(`Finished.`); this.message(`Finished.`);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment