(event: IClickhouseEvent)
| 86 | } |
| 87 | |
| 88 | add(event: IClickhouseEvent) { |
| 89 | // Event-buffer's add() is synchronous (in-memory push). Measured anyway |
| 90 | // for consistency with the other buffers' add-latency tracking. |
| 91 | const start = performance.now(); |
| 92 | this.pendingEvents.push(event); |
| 93 | |
| 94 | if (this.pendingEvents.length >= this.microBatchMaxSize) { |
| 95 | this.flushLocalBuffer(); |
| 96 | } else if (!this.flushTimer) { |
| 97 | this.flushTimer = setTimeout(() => { |
| 98 | this.flushTimer = null; |
| 99 | this.flushLocalBuffer(); |
| 100 | }, this.microBatchIntervalMs); |
| 101 | } |
| 102 | |
| 103 | try { |
| 104 | this.addObserver?.({ |
| 105 | buffer: this.name, |
| 106 | durationMs: performance.now() - start, |
| 107 | }); |
| 108 | } catch { |
| 109 | // never break add on observer failure |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /** Number of events buffered locally in process memory, before Redis. */ |
| 114 | public getPendingLocalCount(): number { |
no test coverage detected