@@ -12,6 +12,7 @@ Examples as below:
12
12
package main
13
13
14
14
import (
15
+ " time"
15
16
" github.com/byte-power/gorich/task"
16
17
)
17
18
@@ -49,6 +50,8 @@ You can also monitor the scheduled jobs via JobStats.
49
50
package main
50
51
51
52
import (
53
+ " fmt"
54
+ " time"
52
55
" github.com/byte-power/gorich/task"
53
56
)
54
57
@@ -65,13 +68,16 @@ func main() {
65
68
}
66
69
67
70
func monitorScheduler () {
68
- // handle all job stats
69
- allJobStats := task.JobStats ()
70
- for jobName , jobStats := range allJobStats {
71
- fmt.Printf (" job %s stat:\n " , jobName)
72
- for _ , stat := range jobStats {
73
- fmt.Println (stat.ToMap ())
71
+ for {
72
+ // handle all job stats
73
+ allJobStats := task.JobStats ()
74
+ for jobName , jobStats := range allJobStats {
75
+ fmt.Printf (" job %s stat:\n " , jobName)
76
+ for _ , stat := range jobStats {
77
+ fmt.Println (stat.ToMap ())
78
+ }
74
79
}
80
+ time.Sleep (5 * time.Second )
75
81
}
76
82
}
77
83
@@ -90,6 +96,8 @@ Notice that Coordinate use a lock that will unlock automatically 5 seconds later
90
96
package main
91
97
92
98
import (
99
+ " fmt"
100
+ " time"
93
101
" github.com/byte-power/gorich/task"
94
102
)
95
103
@@ -110,27 +118,31 @@ func main () {
110
118
go scheduler1.Start ()
111
119
go scheduler2.Start ()
112
120
113
- jobStats := job1.Stats ()
114
- fmt.Println (" job1 stats:" )
115
- for _ , stat := range jobStats {
116
- fmt.Println (stat.ToMap ())
117
- }
121
+ go monitorJob (job1)
122
+ go monitorJob (job2)
118
123
119
- jobStats = job2.Stats ()
120
- fmt.Println (" job2 stats:" )
121
- for _ , stat := range jobStats {
122
- fmt.Println (stat.ToMap ())
123
- }
124
- // stop schedulers after 10 seconds
125
- time.Sleep (10 * time.Second )
124
+
125
+ // stop schedulers after 30 seconds
126
+ time.Sleep (30 * time.Second )
126
127
127
128
scheduler1.Stop (false )
128
129
scheduler2.Stop (false )
129
130
}
130
131
132
+ func monitorJob (job task .Job ) {
133
+ for {
134
+ jobStats := job.Stats ()
135
+ fmt.Printf (" job %s stats:\n " , job.Name ())
136
+ for _ , stat := range jobStats {
137
+ fmt.Println (stat.ToMap ())
138
+ }
139
+ time.Sleep (5 * time.Second )
140
+ }
141
+ }
142
+
131
143
func sum (a , b int ) int {
132
144
return a + b
133
145
}
134
146
```
135
147
136
- See more examples [ here] ( ./example_test.go ) .
148
+ See more examples [ here] ( ./example_test.go ) .
0 commit comments