This repository has been archived by the owner on Jun 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnotifier.go
54 lines (45 loc) · 1.54 KB
/
notifier.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
42
43
44
45
46
47
48
49
50
51
52
53
54
package notifier
import (
"sync"
"time"
"github.com/gosexy/to"
"github.com/rcrowley/go-metrics"
)
var (
wg sync.WaitGroup
eventsReceived = metrics.NewRegisteredMeter("events.received", metrics.DefaultRegistry)
eventsMalformed = metrics.NewRegisteredMeter("events.malformed", metrics.DefaultRegistry)
eventsProcessingFailed = metrics.NewRegisteredMeter("events.failed", metrics.DefaultRegistry)
subsMalformed = metrics.NewRegisteredMeter("subs.malformed", metrics.DefaultRegistry)
sendingFailed = metrics.NewRegisteredMeter("sending.failed", metrics.DefaultRegistry)
senderTimeout time.Duration
resendingTimeout time.Duration
sending = make(map[string]chan notificationPackage)
sendersOkMetrics = make(map[string]metrics.Meter)
sendersFailedMetrics = make(map[string]metrics.Meter)
log Logger
db Database
config *Config
// GetNow allows you to travel in time while testing
GetNow = func() time.Time {
return time.Now()
}
)
// GetWaitGroup return senders wait group
func GetWaitGroup() *sync.WaitGroup {
return &wg
}
// SetLogger allows you to redefine logging in tests
func SetLogger(logger Logger) {
log = logger
}
// SetDb allows you to use mock database in tests
func SetDb(connector Database) {
db = connector
}
// SetSettings allows you to redefine config in tests
func SetSettings(c *Config) {
config = c
senderTimeout = to.Duration(config.Notifier.SenderTimeout)
resendingTimeout = to.Duration(config.Notifier.ResendingTimeout)
}