From c674127784681ed3573c8482576d3efbb242ca31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Sat, 14 Sep 2024 22:36:32 +0200 Subject: [PATCH] test(buffer): disable auto flush on profile --- apps/worker/src/index.ts | 7 ++----- packages/db/src/buffers/buffer.ts | 10 ++++++++-- packages/db/src/buffers/profile-buffer.ts | 1 + 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/worker/src/index.ts b/apps/worker/src/index.ts index a15d1df3..95441ba9 100644 --- a/apps/worker/src/index.ts +++ b/apps/worker/src/index.ts @@ -175,9 +175,7 @@ async function start() { { jobId: 'flushProfiles', repeat: { - every: process.env.BATCH_INTERVAL - ? parseInt(process.env.BATCH_INTERVAL, 10) - : 1000 * 10, + every: 2 * 1000, }, } ); @@ -200,8 +198,7 @@ async function start() { const repeatableJobs = await cronQueue.getRepeatableJobs(); - console.log('Repeatable jobs:'); - console.log(repeatableJobs); + logger.info('Repeatable jobs', { repeatableJobs }); await createInitialSalts(); } diff --git a/packages/db/src/buffers/buffer.ts b/packages/db/src/buffers/buffer.ts index 80099ee6..7658de82 100644 --- a/packages/db/src/buffers/buffer.ts +++ b/packages/db/src/buffers/buffer.ts @@ -42,6 +42,7 @@ export abstract class RedisBuffer { public table: string; public batchSize?: number; public logger: ReturnType; + public disableAutoFlush?: boolean; // abstract methods public abstract onInsert?: OnInsert; @@ -50,9 +51,14 @@ export abstract class RedisBuffer { public abstract find: Find; public abstract findMany: FindMany; - constructor(options: { table: string; batchSize?: number }) { + constructor(options: { + table: string; + batchSize?: number; + disableAutoFlush?: boolean; + }) { this.table = options.table; this.batchSize = options.batchSize; + this.disableAutoFlush = options.disableAutoFlush; this.logger = createLogger({ name: `buffer` }).child({ table: this.table, }); @@ -75,7 +81,7 @@ export abstract class RedisBuffer { `Inserted item into buffer ${this.table}. Current length: ${length}` ); - if (this.batchSize && length >= this.batchSize) { + if (!this.disableAutoFlush && this.batchSize && length >= this.batchSize) { this.logger.info( `Buffer ${this.table} reached batch size (${this.batchSize}). Flushing...` ); diff --git a/packages/db/src/buffers/profile-buffer.ts b/packages/db/src/buffers/profile-buffer.ts index c236946a..4488888d 100644 --- a/packages/db/src/buffers/profile-buffer.ts +++ b/packages/db/src/buffers/profile-buffer.ts @@ -24,6 +24,7 @@ export class ProfileBuffer extends RedisBuffer { super({ table: TABLE_NAMES.profiles, batchSize: 100, + disableAutoFlush: true, }); }