-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgron_test.go
More file actions
62 lines (55 loc) · 956 Bytes
/
Copy pathgron_test.go
File metadata and controls
62 lines (55 loc) · 956 Bytes
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
55
56
57
58
59
60
61
62
package gron
import (
"fmt"
"testing"
"time"
)
func TestRace(t *testing.T) {
Gron(
Every(2),
Seconds(),
Do(func() {
fmt.Println("FireBall!")
}),
Name("Dragon"),
)
Gron(
Every(3),
Seconds(),
Do(func() {
time.Sleep(3 * time.Second)
fmt.Println("Cast Blizzard!")
}),
Name("Lydia"),
)
Gron(
Every(4),
Seconds(),
Do(func() {
panic("Thunderclap! Oops...")
}),
Name("Druid!"),
)
start := time.Now()
counter := 3
// subscribe task events
for ev := range Subscribe() {
switch ev.E {
case Disabled:
fmt.Println("Disabled:", ev.TaskName, ev.At.Format("15:04:05"))
counter--
case Failed:
fmt.Println("Failed:", ev.TaskName, ev.Msg, ev.At.Format("15:04:05"))
Remove(ev.TaskName)
default:
fmt.Println(ev.TaskName, ev.E, ev.At.Format("15:04:05"))
}
if counter == 0 {
break
}
if time.Since(start) > 10*time.Second {
Remove(ev.TaskName)
}
}
fmt.Println("At the end!")
}