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