This commit is contained in:
ppom
2023-03-25 19:12:11 +01:00
parent 5dcbdd865e
commit a637d63826
3 changed files with 25 additions and 5 deletions

View File

@ -31,7 +31,7 @@ type Filter struct {
compiledRegex []regexp.Regexp
patternName, patternWithBraces string
Retry uint
Retry int
RetryPeriod string `yaml:"retry-period"`
retryDuration time.Duration
@ -64,6 +64,7 @@ func (c *Conf) setup() {
filter := stream.Filters[filterName]
filter.stream = stream
filter.name = filterName
filter.matches = make(map[string][]time.Time)
// Parse Duration
retryDuration, err := time.ParseDuration(filter.RetryPeriod)

View File

@ -3,6 +3,7 @@ package app
import (
"bufio"
"flag"
// "fmt"
"log"
"os"
@ -80,13 +81,31 @@ func (a *Action) exec(match string) {
}
}
func (f *Filter) cleanOldMatches(match string) {
now := time.Now()
newMatches := make([]time.Time, 0, len(f.matches[match]))
for _, old := range f.matches[match] {
if old.Add(f.retryDuration).After(now) {
newMatches = append(newMatches, old)
}
}
f.matches[match] = newMatches
}
func (f *Filter) handle() chan *string {
lines := make(chan *string)
go func() {
for line := range lines {
if match := f.match(line); match != "" {
f.execActions(match)
f.cleanOldMatches(match)
f.matches[match] = append(f.matches[match], time.Now())
if len(f.matches[match]) >= f.Retry {
f.execActions(match)
}
}
}
}()