fix(core): Reschedule Insights flushing after skipping for empty buffer (#14637)

This commit is contained in:
Guillaume Jacquart
2025-04-15 11:42:22 +02:00
committed by GitHub
parent 2ca742cb15
commit 513f20a902
2 changed files with 25 additions and 0 deletions

View File

@@ -544,6 +544,29 @@ describe('workflowExecuteAfterHandler - flushEvents', () => {
}
});
test('reschedule flush on no buffered insights', async () => {
// ARRANGE
jest.useFakeTimers();
trxMock.insert.mockClear();
insightsService.startBackgroundProcess();
const flushEventsSpy = jest.spyOn(insightsService, 'flushEvents');
try {
// ACT
await jest.advanceTimersByTimeAsync(31 * 1000);
// ASSERT
expect(flushEventsSpy).toHaveBeenCalledTimes(1);
expect(trxMock.insert).not.toHaveBeenCalled();
// ACT
await jest.advanceTimersByTimeAsync(31 * 1000);
expect(flushEventsSpy).toHaveBeenCalledTimes(2);
} finally {
jest.useRealTimers();
}
});
test('flushes events to the database on shutdown', async () => {
// ARRANGE
trxMock.insert.mockClear();

View File

@@ -259,6 +259,8 @@ export class InsightsService {
async flushEvents() {
// Prevent flushing if there are no events to flush
if (this.bufferedInsights.size === 0) {
// reschedule the timer to flush again
this.startFlushingScheduler();
return;
}