-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
74 lines (63 loc) · 1.87 KB
/
options.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package shutdown
import "time"
type Option func(*Manager)
// WithOSExit toggles calling os.Exit.
func WithOSExit(b bool) Option {
return func(m *Manager) {
m.performOSExit = b
}
}
// WithLogPrinter sets the logprinter
func WithLogPrinter(fn func(format string, v ...interface{})) Option {
return func(m *Manager) {
m.logger = logWrapper{w: fn}
}
}
// WithLogLockTimeouts toggles logging timeouts. Default: true
func WithLogLockTimeouts(logTimeouts bool) Option {
return func(m *Manager) {
m.logLockTimeouts = logTimeouts
}
}
// WithOnTimeout allows you to get a notification if a shutdown stage times out.
// The stage and the context of the hanging shutdown/lock function is returned.
func WithOnTimeout(fn func(Stage, string)) Option {
return func(m *Manager) {
m.onTimeOut = fn
}
}
// WithTimeout sets maximum delay to wait for each stage to finish.
// When the timeout has expired for a stage the next stage will be initiated.
func WithTimeout(d time.Duration) Option {
return func(m *Manager) {
for i := range m.timeouts {
m.timeouts[i] = d
}
}
}
// WithTimeoutN set maximum delay to wait for a specific stage to finish.
// When the timeout expired for a stage the next stage will be initiated.
// The stage can be obtained by using the exported variables called 'Stage1, etc.
func WithTimeoutN(s Stage, d time.Duration) Option {
return func(m *Manager) {
m.timeouts[s.n] = d
}
}
// WithWarningPrefix is printed before warnings.
func WithWarningPrefix(s string) Option {
return func(m *Manager) {
m.warningPrefix = s
}
}
// WithErrorPrefix is printed before errors.
func WithnErrorPrefix(s string) Option {
return func(m *Manager) {
m.warningPrefix = s
}
}
// WithStatusTimer is the time between logging which notifiers are waiting to finish.
func WithStatusTimer(statusTimer time.Duration) Option {
return func(m *Manager) {
m.statusTimer = statusTimer
}
}