mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
chore(core): Refactor logging for insights flushing (#15978)
This commit is contained in:
@@ -75,22 +75,30 @@ export class InsightsCollectionService {
|
||||
|
||||
startFlushingTimer() {
|
||||
this.isAsynchronouslySavingInsights = true;
|
||||
this.stopFlushingTimer();
|
||||
this.scheduleFlushing();
|
||||
this.logger.debug('Started flushing timer');
|
||||
}
|
||||
|
||||
scheduleFlushing() {
|
||||
this.cancelScheduledFlushing();
|
||||
this.flushInsightsRawBufferTimer = setTimeout(
|
||||
async () => await this.flushEvents(),
|
||||
this.insightsConfig.flushIntervalSeconds * 1000,
|
||||
);
|
||||
this.logger.debug('Started flushing timer');
|
||||
}
|
||||
|
||||
stopFlushingTimer() {
|
||||
cancelScheduledFlushing() {
|
||||
if (this.flushInsightsRawBufferTimer !== undefined) {
|
||||
clearTimeout(this.flushInsightsRawBufferTimer);
|
||||
this.flushInsightsRawBufferTimer = undefined;
|
||||
this.logger.debug('Stopped flushing timer');
|
||||
}
|
||||
}
|
||||
|
||||
stopFlushingTimer() {
|
||||
this.cancelScheduledFlushing();
|
||||
this.logger.debug('Stopped flushing timer');
|
||||
}
|
||||
|
||||
async shutdown() {
|
||||
this.stopFlushingTimer();
|
||||
|
||||
@@ -228,12 +236,12 @@ export class InsightsCollectionService {
|
||||
// Prevent flushing if there are no events to flush
|
||||
if (this.bufferedInsights.size === 0) {
|
||||
// reschedule the timer to flush again
|
||||
this.startFlushingTimer();
|
||||
this.scheduleFlushing();
|
||||
return;
|
||||
}
|
||||
|
||||
// Stop timer to prevent concurrent flush from timer
|
||||
this.stopFlushingTimer();
|
||||
this.cancelScheduledFlushing();
|
||||
|
||||
// Copy the buffer to a new set to avoid concurrent modification
|
||||
// while we are flushing the events
|
||||
@@ -250,7 +258,7 @@ export class InsightsCollectionService {
|
||||
this.bufferedInsights.add(event);
|
||||
}
|
||||
} finally {
|
||||
this.startFlushingTimer();
|
||||
this.scheduleFlushing();
|
||||
this.flushesInProgress.delete(flushPromise!);
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user