From 51c6d7ad8df0c55fd51dfe11604f32d887655d74 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Mon, 15 Dec 2025 09:16:19 -0500 Subject: [PATCH] refactor: Update TTL configuration for completed jobs in InMemoryJobStore - Changed the TTL for completed jobs from 5 minutes to 0, allowing for immediate cleanup. - Enhanced cleanup logic to respect the new TTL setting, improving resource management. - Updated comments for clarity on the behavior of the TTL configuration. --- .../src/stream/implementations/InMemoryJobStore.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/api/src/stream/implementations/InMemoryJobStore.ts b/packages/api/src/stream/implementations/InMemoryJobStore.ts index 0e60d28010..6161c58c33 100644 --- a/packages/api/src/stream/implementations/InMemoryJobStore.ts +++ b/packages/api/src/stream/implementations/InMemoryJobStore.ts @@ -26,8 +26,8 @@ export class InMemoryJobStore implements IJobStore { private contentState = new Map(); private cleanupInterval: NodeJS.Timeout | null = null; - /** Time to keep completed jobs before cleanup (5 minutes) */ - private ttlAfterComplete = 300000; + /** Time to keep completed jobs before cleanup (0 = immediate) */ + private ttlAfterComplete = 0; /** Maximum number of concurrent jobs */ private maxJobs = 1000; @@ -119,8 +119,11 @@ export class InMemoryJobStore implements IJobStore { for (const [streamId, job] of this.jobs) { const isFinished = ['complete', 'error', 'aborted'].includes(job.status); - if (isFinished && job.completedAt && now - job.completedAt > this.ttlAfterComplete) { - toDelete.push(streamId); + if (isFinished && job.completedAt) { + // TTL of 0 means immediate cleanup, otherwise wait for TTL to expire + if (this.ttlAfterComplete === 0 || now - job.completedAt > this.ttlAfterComplete) { + toDelete.push(streamId); + } } }