filters don't have their own goroutine anymore
This commit is contained in:
parent
d90e88d5eb
commit
2243dda49a
@ -116,11 +116,7 @@ func (f *Filter) cleanOldMatches(match string) {
|
||||
f.matches[match] = newMatches
|
||||
}
|
||||
|
||||
func (f *Filter) handle() chan *string {
|
||||
lines := make(chan *string)
|
||||
|
||||
go func() {
|
||||
for line := range lines {
|
||||
func (f *Filter) handle(line *string) {
|
||||
if match := f.match(line); match != "" {
|
||||
|
||||
entry := LogEntry{time.Now(), match, f.stream.name, f.name, false}
|
||||
@ -140,26 +136,11 @@ func (f *Filter) handle() chan *string {
|
||||
logs <- entry
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return lines
|
||||
}
|
||||
|
||||
func (s *Stream) handle(endedSignal chan *Stream) {
|
||||
log.Printf("INFO %s: start %s\n", s.name, s.Cmd)
|
||||
|
||||
lines := cmdStdout(s.Cmd)
|
||||
|
||||
var filterInputs = make([]chan *string, 0, len(s.Filters))
|
||||
for _, filter := range s.Filters {
|
||||
filterInputs = append(filterInputs, filter.handle())
|
||||
}
|
||||
defer func() {
|
||||
for _, filterInput := range filterInputs {
|
||||
close(filterInput)
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
select {
|
||||
case line, ok := <-lines:
|
||||
@ -167,8 +148,8 @@ func (s *Stream) handle(endedSignal chan *Stream) {
|
||||
endedSignal <- s
|
||||
return
|
||||
}
|
||||
for _, filterInput := range filterInputs {
|
||||
filterInput <- line
|
||||
for _, filter := range s.Filters {
|
||||
filter.handle(line)
|
||||
}
|
||||
case _, ok := <-stopStreams:
|
||||
if !ok {
|
||||
|
Loading…
Reference in New Issue
Block a user