filters don't have their own goroutine anymore

This commit is contained in:
ppom 2023-09-09 20:36:41 +02:00
parent d90e88d5eb
commit 2243dda49a

View File

@ -116,11 +116,7 @@ func (f *Filter) cleanOldMatches(match string) {
f.matches[match] = newMatches f.matches[match] = newMatches
} }
func (f *Filter) handle() chan *string { func (f *Filter) handle(line *string) {
lines := make(chan *string)
go func() {
for line := range lines {
if match := f.match(line); match != "" { if match := f.match(line); match != "" {
entry := LogEntry{time.Now(), match, f.stream.name, f.name, false} entry := LogEntry{time.Now(), match, f.stream.name, f.name, false}
@ -140,26 +136,11 @@ func (f *Filter) handle() chan *string {
logs <- entry logs <- entry
} }
} }
}()
return lines
}
func (s *Stream) handle(endedSignal chan *Stream) { func (s *Stream) handle(endedSignal chan *Stream) {
log.Printf("INFO %s: start %s\n", s.name, s.Cmd) log.Printf("INFO %s: start %s\n", s.name, s.Cmd)
lines := cmdStdout(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 { for {
select { select {
case line, ok := <-lines: case line, ok := <-lines:
@ -167,8 +148,8 @@ func (s *Stream) handle(endedSignal chan *Stream) {
endedSignal <- s endedSignal <- s
return return
} }
for _, filterInput := range filterInputs { for _, filter := range s.Filters {
filterInput <- line filter.handle(line)
} }
case _, ok := <-stopStreams: case _, ok := <-stopStreams:
if !ok { if !ok {