Emit equity candles on schedule to avoid stalled charts

This commit is contained in:
dirtydishes 2026-01-10 16:08:23 -05:00
parent 980bb4f1b1
commit 9edf8fcbc5
3 changed files with 41 additions and 0 deletions

View file

@ -329,6 +329,18 @@ const run = async () => {
let droppedLate = 0;
let lastLateLog = Date.now();
const flushExpired = async () => {
const expired = aggregator.flushExpired(Date.now());
for (const candle of expired) {
const validated = EquityCandleSchema.parse(candle);
await emitCandle(clickhouse, js, redis, validated, env.CANDLE_CACHE_LIMIT);
}
};
const flushTimer = setInterval(() => {
void flushExpired();
}, 1000);
const loop = async () => {
for await (const msg of subscription.messages) {
try {
@ -365,6 +377,8 @@ const run = async () => {
const shutdown = async (signal: string) => {
logger.info("service stopping", { signal });
clearInterval(flushTimer);
await flushExpired();
const remaining = aggregator.drain();
for (const candle of remaining) {
const validated = EquityCandleSchema.parse(candle);