blob: 70a9965c550ce815ebe616768c475c324a168950 (
plain) (
blame)
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
75
76
77
78
79
80
81
82
|
package rutina
import (
"context"
"time"
)
type Options struct {
ParentContext context.Context
ListenOsSignals bool
Logger func(format string, v ...interface{})
Errors chan error
}
func (o *Options) SetParentContext(ctx context.Context) *Options {
o.ParentContext = ctx
return o
}
func (o *Options) SetListenOsSignals(listenOsSignals bool) *Options {
o.ListenOsSignals = listenOsSignals
return o
}
func (o *Options) SetLogger(l logger) *Options {
o.Logger = l
return o
}
func (o *Options) SetErrors(errCh chan error) *Options {
o.Errors = errCh
return o
}
var Opt = &Options{
ParentContext: context.Background(),
ListenOsSignals: false,
Logger: nil,
Errors: nil,
}
type Policy int
const (
DoNothing Policy = iota
Shutdown
Restart
)
type RunOptions struct {
OnDone Policy
OnError Policy
Timeout *time.Duration
MaxCount *int
}
func (rp *RunOptions) SetOnDone(policy Policy) *RunOptions {
rp.OnDone = policy
return rp
}
func (rp *RunOptions) SetOnError(policy Policy) *RunOptions {
rp.OnError = policy
return rp
}
func (rp *RunOptions) SetTimeout(timeout time.Duration) *RunOptions {
rp.Timeout = &timeout
return rp
}
func (rp *RunOptions) SetMaxCount(maxCount int) *RunOptions {
rp.MaxCount = &maxCount
return rp
}
var RunOpt = &RunOptions{
OnDone: DoNothing,
OnError: Shutdown,
Timeout: nil,
MaxCount: nil,
}
|