-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.go
57 lines (49 loc) · 918 Bytes
/
main.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
55
56
57
package main
import (
"context"
"log"
"time"
"github.com/appleboy/graceful"
)
func main() {
m := graceful.NewManager(
graceful.WithLogger(logger{}),
)
// Add job 01
m.AddRunningJob(func(ctx context.Context) error {
for {
select {
case <-ctx.Done():
return nil
default:
log.Println("working job 01")
time.Sleep(1 * time.Second)
}
}
})
// Add job 02
m.AddRunningJob(func(ctx context.Context) error {
for {
select {
case <-ctx.Done():
return nil
default:
log.Println("working job 02")
time.Sleep(500 * time.Millisecond)
}
}
})
// Add shutdown 01
m.AddShutdownJob(func() error {
log.Println("shutdown job 01 and wait 1 second")
time.Sleep(1 * time.Second)
return nil
})
// Add shutdown 02
m.AddShutdownJob(func() error {
log.Println("shutdown job 02 and wait 2 second")
time.Sleep(2 * time.Second)
return nil
})
<-m.Done()
}