summaryrefslogtreecommitdiff
path: root/error_buffer.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-23 13:15:33 +0300
committerWolfy-J <[email protected]>2018-06-23 13:15:33 +0300
commit38d694411abbdb0c31b08b96452fa0604a93418a (patch)
tree828492153bd4893347534e6ee9858bbb4d45f233 /error_buffer.go
parent14a54572d7a3754aeb81d3dc9949276b7fff04fe (diff)
support for realtime error aggegration
Diffstat (limited to 'error_buffer.go')
-rw-r--r--error_buffer.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/error_buffer.go b/error_buffer.go
index fcf566c8..27f35e78 100644
--- a/error_buffer.go
+++ b/error_buffer.go
@@ -5,10 +5,22 @@ import (
"sync"
)
+// EventStderrOutput - is triggered when worker sends data into stderr. The context is output data in []bytes form.
+const EventStderrOutput = 1900
+
// thread safe errBuffer
type errBuffer struct {
mu sync.Mutex
buffer *bytes.Buffer
+ lsn func(event int, ctx interface{})
+}
+
+// Listen attaches error stream even listener.
+func (b *errBuffer) Listen(l func(event int, ctx interface{})) {
+ b.mu.Lock()
+ defer b.mu.Unlock()
+
+ b.lsn = l
}
// Len returns the number of bytes of the unread portion of the errBuffer;
@@ -27,6 +39,10 @@ func (b *errBuffer) Write(p []byte) (n int, err error) {
b.mu.Lock()
defer b.mu.Unlock()
+ if b.lsn != nil {
+ b.lsn(EventStderrOutput, p)
+ }
+
return b.buffer.Write(p)
}