Scheduler: refresh DNS provider domain lists on interval (#69)
The host scheduler already checked wildcard cert expiry; add the second half of the scheduler controller — DnsProvider.refreshAllDomains() re-syncs every provider's domain list (get -> updateDomains, per-provider errors isolated), scheduled 30s after start and every 24h alongside the cert check. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -149,6 +149,28 @@ class DnsProvider extends Table{
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Re-sync every configured provider's domain list from its API. Mirrors the
|
||||||
|
// manual /dns/domain/refresh/:item route (get -> updateDomains) across all
|
||||||
|
// providers; used by the host scheduler. Never throws — one bad provider
|
||||||
|
// (e.g. a revoked key) must not abort the rest.
|
||||||
|
static async refreshAllDomains(){
|
||||||
|
let ids;
|
||||||
|
try{
|
||||||
|
ids = await this.list();
|
||||||
|
}catch(error){
|
||||||
|
console.error('refreshAllDomains: could not list providers', error.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for(let id of ids){
|
||||||
|
try{
|
||||||
|
let provider = await this.get(id);
|
||||||
|
await provider.updateDomains();
|
||||||
|
}catch(error){
|
||||||
|
console.error('refreshAllDomains: provider', id, error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get api(){
|
get api(){
|
||||||
return new this.constructor.Provider(this);
|
return new this.constructor.Provider(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const conf = require('@simpleworkjs/conf');
|
const conf = require('@simpleworkjs/conf');
|
||||||
const {Host} = require('../models/host');
|
const {Host} = require('../models/host');
|
||||||
|
const {DnsProvider} = require('../models').models;
|
||||||
|
|
||||||
|
|
||||||
function hostSchedulerService(){
|
function hostSchedulerService(){
|
||||||
@@ -29,8 +30,14 @@ function hostSchedulerService(){
|
|||||||
// Ensures certificates are renewed well before expiration
|
// Ensures certificates are renewed well before expiration
|
||||||
setInterval(Host.checkWildcardForRenew.bind(Host), conf.service.hostScheduler.interval);
|
setInterval(Host.checkWildcardForRenew.bind(Host), conf.service.hostScheduler.interval);
|
||||||
|
|
||||||
|
// Refresh each DNS provider's domain list on the same cadence so domains
|
||||||
|
// added/removed at the provider are picked up without a manual refresh.
|
||||||
|
setTimeout(DnsProvider.refreshAllDomains.bind(DnsProvider), conf.service.hostScheduler.initial);
|
||||||
|
setInterval(DnsProvider.refreshAllDomains.bind(DnsProvider), conf.service.hostScheduler.interval);
|
||||||
|
|
||||||
console.log('Host scheduler service initialized');
|
console.log('Host scheduler service initialized');
|
||||||
console.log('- Wildcard cert check: 30s after start, then every 24h');
|
console.log('- Wildcard cert check: 30s after start, then every 24h');
|
||||||
|
console.log('- DNS provider domain refresh: 30s after start, then every 24h');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(conf.service.hostScheduler.enabled !== false) hostSchedulerService();
|
if(conf.service.hostScheduler.enabled !== false) hostSchedulerService();
|
||||||
|
|||||||
Reference in New Issue
Block a user