mirror of
https://github.com/ptarmiganlabs/butler-sos.git
synced 2025-12-19 17:58:18 -05:00
Add overlapping execution prevention to proxy sessions timer
- Add isCollecting flag to prevent overlapping proxy session polls - Add warning log when skipping intervals due to long-running operations - Consistent execution management pattern across both health check and proxy session timers Co-authored-by: mountaindude <1029262+mountaindude@users.noreply.github.com>
This commit is contained in:
@@ -328,10 +328,13 @@ export async function getProxySessionStatsFromSense(serverName, host, virtualPro
|
||||
* This function configures a periodic task that polls all configured Sense servers
|
||||
* and their virtual proxies for user session information. The gathered data is then
|
||||
* processed and sent to the configured destinations.
|
||||
* Uses a flag to prevent overlapping executions if session polling takes longer than the polling interval.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
export function setupUserSessionsTimer() {
|
||||
let isCollecting = false;
|
||||
|
||||
globals.logger.debug(
|
||||
`PROXY SESSIONS: Monitor user sessions for these servers/virtual proxies: ${JSON.stringify(
|
||||
globals.serverList,
|
||||
@@ -342,35 +345,48 @@ export function setupUserSessionsTimer() {
|
||||
|
||||
// Configure timer for getting user session data from Sense proxy API
|
||||
setInterval(async () => {
|
||||
globals.logger.verbose('PROXY SESSIONS: Event started: Poll user sessions');
|
||||
// Prevent overlapping executions
|
||||
if (isCollecting) {
|
||||
globals.logger.warn(
|
||||
'PROXY SESSIONS: Previous session polling still in progress, skipping this interval'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Process servers sequentially to avoid overwhelming the Sense servers
|
||||
for (const server of globals.serverList) {
|
||||
if (server.userSessions.enable) {
|
||||
const tags = getServerTags(globals.logger, server);
|
||||
isCollecting = true;
|
||||
try {
|
||||
globals.logger.verbose('PROXY SESSIONS: Event started: Poll user sessions');
|
||||
|
||||
// Process virtual proxies sequentially
|
||||
for (const virtualProxy of server.userSessions.virtualProxies) {
|
||||
globals.logger.debug(
|
||||
`PROXY SESSIONS: Getting user sessions for host=${
|
||||
server.userSessions.host
|
||||
}, virtual proxy=${JSON.stringify(virtualProxy, null, 2)}`
|
||||
);
|
||||
// Process servers sequentially to avoid overwhelming the Sense servers
|
||||
for (const server of globals.serverList) {
|
||||
if (server.userSessions.enable) {
|
||||
const tags = getServerTags(globals.logger, server);
|
||||
|
||||
try {
|
||||
await getProxySessionStatsFromSense(
|
||||
server.serverName,
|
||||
server.userSessions.host,
|
||||
virtualProxy.virtualProxy,
|
||||
tags
|
||||
);
|
||||
} catch (err) {
|
||||
globals.logger.error(
|
||||
`PROXY SESSIONS: Error getting session stats for server '${server.serverName}' (${server.userSessions.host}), virtual proxy '${virtualProxy.virtualProxy}': ${globals.getErrorMessage(err)}`
|
||||
// Process virtual proxies sequentially
|
||||
for (const virtualProxy of server.userSessions.virtualProxies) {
|
||||
globals.logger.debug(
|
||||
`PROXY SESSIONS: Getting user sessions for host=${
|
||||
server.userSessions.host
|
||||
}, virtual proxy=${JSON.stringify(virtualProxy, null, 2)}`
|
||||
);
|
||||
|
||||
try {
|
||||
await getProxySessionStatsFromSense(
|
||||
server.serverName,
|
||||
server.userSessions.host,
|
||||
virtualProxy.virtualProxy,
|
||||
tags
|
||||
);
|
||||
} catch (err) {
|
||||
globals.logger.error(
|
||||
`PROXY SESSIONS: Error getting session stats for server '${server.serverName}' (${server.userSessions.host}), virtual proxy '${virtualProxy.virtualProxy}': ${globals.getErrorMessage(err)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
isCollecting = false;
|
||||
}
|
||||
}, globals.config.get('Butler-SOS.userSessions.pollingInterval'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user