feat(ingest): batch event writes and harden transport

This commit is contained in:
William Valentin
2026-03-26 11:22:42 -07:00
parent 43877a5448
commit 6605780b58
4 changed files with 65 additions and 9 deletions
-4
View File
@@ -26,9 +26,5 @@ func (p *Publisher) Close() {
}
func (p *Publisher) Publish(ctx context.Context, data []byte) error {
ctx, cancel := context.WithTimeout(ctx, p.timeout)
defer cancel()
_ = ctx
return p.conn.Publish(p.topic, data)
}
+7 -2
View File
@@ -221,7 +221,7 @@ func (e *Emitter) Emit(ctx context.Context, event Event) error {
e.buffer = append(e.buffer, event)
if len(e.buffer) >= e.bufferSize {
return e.Flush(ctx)
return e.flushLocked(ctx)
}
return nil
}
@@ -235,6 +235,11 @@ func (e *Emitter) Flush(ctx context.Context) error {
return fmt.Errorf("emitter is closed")
}
return e.flushLocked(ctx)
}
// flushLocked sends buffered events. Caller must hold e.mu.
func (e *Emitter) flushLocked(ctx context.Context) error {
if len(e.buffer) == 0 {
return nil
}
@@ -281,7 +286,7 @@ func (e *Emitter) Close(ctx context.Context) error {
}
if len(e.buffer) > 0 {
_ = e.Flush(ctx)
_ = e.flushLocked(ctx)
}
return nil