-
Notifications
You must be signed in to change notification settings - Fork 17
/
filter.go
41 lines (34 loc) · 896 Bytes
/
filter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"time"
"github.com/AdRoll/baker"
)
var LazyFilterDesc = baker.FilterDesc{
Name: "LazyFilter",
New: NewLazyFilter,
Config: &LazyFilterConfig{},
Help: "This lazy filter does nothing during working time but drops all records between 6pm and 9am",
}
type LazyFilterConfig struct {
Stakhanovite bool `help:"If true, then only discard records after 8pm"`
}
type LazyFilter struct {
stakhanovite bool
}
func NewLazyFilter(cfg baker.FilterParams) (baker.Filter, error) {
dcfg := cfg.DecodedConfig.(*LazyFilterConfig)
return &LazyFilter{stakhanovite: dcfg.Stakhanovite}, nil
}
func (f *LazyFilter) Process(l baker.Record, next func(baker.Record)) {
h := time.Now().Hour()
upperLimit := 18
if f.stakhanovite {
upperLimit = 20
}
if h >= 9 && h <= upperLimit {
next(l)
}
}
func (f *LazyFilter) Stats() baker.FilterStats {
return baker.FilterStats{}
}