diff --git a/src/apps/history-writer.mjs b/src/apps/history-writer.mjs index 263674f..f7c8764 100644 --- a/src/apps/history-writer.mjs +++ b/src/apps/history-writer.mjs @@ -229,6 +229,12 @@ await refreshQuoteLifecycleRetentionState().catch((error) => { state.retention_error = serializeError(error); }); +const quoteLifecycleRetentionMaintenanceTimer = setInterval(() => { + void maybeRunQuoteLifecycleRetentionMaintenance(); +}, quoteLifecycleRetentionMaintenanceIntervalMs); +quoteLifecycleRetentionMaintenanceTimer.unref?.(); +await maybeRunQuoteLifecycleRetentionMaintenance({ force: true }); + for (const historyConsumer of durableConsumers) { await runHistoryConsumer(historyConsumer); } @@ -770,6 +776,7 @@ function resumeConsumers() { } async function shutdown() { + clearInterval(quoteLifecycleRetentionMaintenanceTimer); await controlApi.close().catch(() => {}); await Promise.allSettled([ ...durableConsumers.map((historyConsumer) => historyConsumer.disconnect()), diff --git a/test/history-writer-static.test.mjs b/test/history-writer-static.test.mjs index 43a86ad..7efdbef 100644 --- a/test/history-writer-static.test.mjs +++ b/test/history-writer-static.test.mjs @@ -24,6 +24,9 @@ test('history writer replays durable topics but joins the raw quote firehose liv assert.match(source, /runQuoteLifecycleRetentionMaintenance/); assert.match(source, /loadQuoteLifecycleRetentionSummary/); assert.match(source, /maybeRunQuoteLifecycleRetentionMaintenance/); + assert.match(source, /quoteLifecycleRetentionMaintenanceTimer\s*=\s*setInterval/); + assert.match(source, /maybeRunQuoteLifecycleRetentionMaintenance\(\{\s*force:\s*true\s*\}\)/); + assert.match(source, /clearInterval\(quoteLifecycleRetentionMaintenanceTimer\)/); assert.match(source, /retention_mode/); assert.match(source, /storage_pressure/); assert.doesNotMatch(source, /RetainRecentMs/);