feat: make background polling disablable with on-demand fallback
All checks were successful
Build and Push Docker Image / build (push) Successful in 27s
All checks were successful
Build and Push Docker Image / build (push) Successful in 27s
- Set POLL_INTERVAL=0, off, false, or disabled to disable background polling - When disabled, data is fetched on-demand when a user opens the dashboard - On-demand results cached for 30s so other users benefit from fresh data - A user with a faster refresh rate keeps the cache warm for everyone - When polling is enabled, behaviour is unchanged (default 5s)
This commit is contained in:
@@ -7,7 +7,11 @@ const {
|
||||
getRadarrInstances
|
||||
} = require('./config');
|
||||
|
||||
const POLL_INTERVAL = parseInt(process.env.POLL_INTERVAL, 10) || 5000;
|
||||
const rawPollInterval = (process.env.POLL_INTERVAL || '').toLowerCase();
|
||||
const POLL_INTERVAL = (rawPollInterval === 'off' || rawPollInterval === 'false' || rawPollInterval === 'disabled')
|
||||
? 0
|
||||
: (parseInt(process.env.POLL_INTERVAL, 10) || 5000);
|
||||
const POLLING_ENABLED = POLL_INTERVAL > 0;
|
||||
|
||||
let polling = false;
|
||||
|
||||
@@ -125,8 +129,9 @@ async function pollAllServices() {
|
||||
})
|
||||
]);
|
||||
|
||||
// Aggregate and store in cache (TTL slightly longer than poll interval to avoid gaps)
|
||||
const cacheTTL = POLL_INTERVAL * 3;
|
||||
// When polling is active, TTL is 3x interval to avoid gaps between polls
|
||||
// When polling is disabled (on-demand), use 30s so data refreshes on next request after expiry
|
||||
const cacheTTL = POLLING_ENABLED ? POLL_INTERVAL * 3 : 30000;
|
||||
|
||||
// SABnzbd
|
||||
const firstSabQueue = sabQueues[0] && sabQueues[0].data && sabQueues[0].data.queue;
|
||||
@@ -182,6 +187,10 @@ async function pollAllServices() {
|
||||
let intervalHandle = null;
|
||||
|
||||
function startPoller() {
|
||||
if (!POLLING_ENABLED) {
|
||||
console.log(`[Poller] Background polling disabled (POLL_INTERVAL=${process.env.POLL_INTERVAL || 'not set'}). Data will be fetched on-demand.`);
|
||||
return;
|
||||
}
|
||||
console.log(`[Poller] Starting background poller (interval: ${POLL_INTERVAL}ms)`);
|
||||
// Run immediately, then on interval
|
||||
pollAllServices();
|
||||
@@ -196,4 +205,4 @@ function stopPoller() {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { startPoller, stopPoller, POLL_INTERVAL };
|
||||
module.exports = { startPoller, stopPoller, pollAllServices, POLL_INTERVAL, POLLING_ENABLED };
|
||||
|
||||
Reference in New Issue
Block a user