-
Notifications
You must be signed in to change notification settings - Fork 0
/
subscriber.go
42 lines (31 loc) · 970 Bytes
/
subscriber.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
package main
import (
"log"
"time"
"github.com/myzhan/boomer"
)
// This is an example about how to subscribe to boomer's internal events.
func foo() {
start := time.Now()
time.Sleep(100 * time.Millisecond)
elapsed := time.Since(start)
boomer.RecordSuccess("http", "foo", elapsed.Nanoseconds()/int64(time.Millisecond), int64(10))
}
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
boomer.Events.Subscribe("boomer:spawn", func(workers int, spawnRate float64) {
log.Println("The master asks me to spawn", workers, "goroutines with a spawn rate of", spawnRate, "per second.")
})
boomer.Events.Subscribe("boomer:stop", func() {
log.Println("The master asks me to stop.")
})
boomer.Events.Subscribe("boomer:quit", func() {
log.Println("Boomer is quitting now, may be the master asks it to do so, or it receives one of SIGINT and SIGTERM.")
})
task := &boomer.Task{
Name: "foo",
Weight: 10,
Fn: foo,
}
boomer.Run(task)
}