add cacheable dns, stagger start times

This commit is contained in:
Alex Holliday
2025-10-28 22:41:05 -07:00
parent bd2ba804ee
commit 30a9309bd8
3 changed files with 18 additions and 3 deletions
@@ -35,8 +35,12 @@ class SuperSimpleQueue {
this.scheduler.addTemplate("monitor-job", this.helper.getMonitorJob());
const monitors = await this.db.monitorModule.getAllMonitors();
for (const monitor of monitors) {
await this.addJob(monitor._id, monitor);
const randomOffset = Math.floor(Math.random() * monitor.interval);
setTimeout(() => {
this.addJob(monitor);
}, randomOffset);
}
return true;
} catch (error) {
this.logger.error({
@@ -1,3 +1,4 @@
import CacheableLookup from "cacheable-lookup";
const SERVICE_NAME = "NetworkService";
class NetworkService {
@@ -15,7 +16,6 @@ class NetworkService {
this.NETWORK_ERROR = 5000;
this.PING_ERROR = 5001;
this.axios = axios;
this.got = got;
this.https = https;
this.jmespath = jmespath;
this.GameDig = GameDig;
@@ -26,6 +26,16 @@ class NetworkService {
this.net = net;
this.stringService = stringService;
this.settingsService = settingsService;
const cacheable = new CacheableLookup();
this.got = got.extend({
dnsCache: cacheable,
timeout: {
request: 30000,
},
retry: { limit: 1 },
});
}
// Helper functions