(event: IClickhouseBotEvent)
| 25 | } |
| 26 | |
| 27 | async add(event: IClickhouseBotEvent) { |
| 28 | return this.timeAdd(async () => { |
| 29 | try { |
| 30 | const result = await this.redis |
| 31 | .multi() |
| 32 | .rpush(this.redisKey, JSON.stringify(event)) |
| 33 | .llen(this.redisKey) |
| 34 | .exec(); |
| 35 | |
| 36 | const bufferLength = (result?.[1]?.[1] as number) ?? 0; |
| 37 | if (bufferLength >= this.batchSize) { |
| 38 | await this.tryFlush({ trigger: 'add' }); |
| 39 | } |
| 40 | } catch (error) { |
| 41 | this.logger.error({ err: error }, 'Failed to add bot event'); |
| 42 | } |
| 43 | }); |
| 44 | } |
| 45 | |
| 46 | async processBuffer() { |
| 47 | const lrangeStart = performance.now(); |
no test coverage detected