Skip to content

Commit

Permalink
chore: add insert logs
Browse files Browse the repository at this point in the history
  • Loading branch information
sasicodes committed Jul 25, 2024
1 parent 7a87571 commit 01955a4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions apps/cron/src/services/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const flushEvents = async (): Promise<void> => {
const length = await rLength(QUEUE_KEY)
// Loop as batch of BATCH_SIZE events
for (let i = 0; i < length; i += BATCH_SIZE) {
const startTime = Date.now()

// pick BATCH_SIZE events from the start of the queue (for eg 0 to 4999)
const rawEvents = await rLoad(QUEUE_KEY, i, BATCH_SIZE - 1)
const events: Record<string, any>[] = rawEvents.map((event) =>
Expand All @@ -23,6 +25,12 @@ const flushEvents = async (): Promise<void> => {
})
await rTrim(QUEUE_KEY, events.length)
}

const endTime = Date.now()
const timeTaken = endTime - startTime
console.log(
`[cron] tower events - batch inserted ${events.length} events to clickhouse in ${timeTaken}ms`
)
}
} catch (error) {
console.error('[cron] Error flushing tower events', error)
Expand Down

0 comments on commit 01955a4

Please sign in to comment.