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.
This commit is contained in:
Danny Avila 2025-12-15 09:16:19 -05:00
parent e01684a30a
commit 51c6d7ad8d
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956

View file

@ -26,8 +26,8 @@ export class InMemoryJobStore implements IJobStore {
private contentState = new Map<string, ContentState>();
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);
}
}
}