-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
77 lines (57 loc) · 1.44 KB
/
config.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
75
76
77
package bees
import (
"time"
)
// config - configuration struct for WorkerPool used only in Create method
type config struct {
Capacity int64
KeepAliveTimeout time.Duration
TimeoutJitter int64 // additional random timeout in ms
GracefulTimeout time.Duration
TaskChLen int
}
type logger interface {
Printf(format string, args ...interface{})
}
type Option interface {
apply(cfg *config)
}
type jitterOption int
func (j jitterOption) apply(cfg *config) {
cfg.TimeoutJitter = int64(j)
}
// WithJitter - add timeout jitter for workers
func WithJitter(jitter int) Option {
return jitterOption(jitter)
}
var WithoutJitter = jitterOption(1)
type keepAliveOption time.Duration
func (k keepAliveOption) apply(cfg *config) {
cfg.KeepAliveTimeout = time.Duration(k)
}
// WithKeepAlive - add keep alive timeout for workers
func WithKeepAlive(k time.Duration) Option {
return keepAliveOption(k)
}
type capacity int
func (m capacity) apply(cfg *config) {
cfg.Capacity = int64(m)
}
// WithCapacity - add max capacity for worker pool
func WithCapacity(m int64) Option {
return capacity(m)
}
type gracefulTimeout time.Duration
func WithGracefulTimeout(t time.Duration) Option {
return gracefulTimeout(t)
}
func (t gracefulTimeout) apply(cfg *config) {
cfg.GracefulTimeout = time.Duration(t)
}
type taskChLen int
func WithTaskLen(t int) Option {
return taskChLen(t)
}
func (t taskChLen) apply(cfg *config) {
cfg.TaskChLen = int(t)
}