-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.go
82 lines (73 loc) · 1.47 KB
/
info.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
78
79
80
81
82
package processor
import (
"time"
)
// Info the info of BatchHandler.
//
// Note:
// If sequence is necessary, make sure that per worker count is one.
// Multiple goroutines cannot guarantee the order in which data is processed.
type Info struct {
// used to get reader from otkafka.ReaderMaker.
// default: "default"
Name string
// reader workers count.
// default: 1
ReadWorker int
// batch workers count.
// default: 1
BatchWorker int
// data size for batch processing.
// default: 1
BatchSize int
// handler workers count.
HandleWorker int
// the size of the data channel.
// default: 100
ChanSize int
// run the batchFunc automatically at specified intervals, avoid not executing without reaching BatchSize
// default: 30s
AutoBatchInterval time.Duration
}
func (i *Info) name() string {
if i.Name == "" {
return "default"
}
return i.Name
}
func (i *Info) readWorker() int {
if i.ReadWorker <= 0 {
return 1
}
return i.ReadWorker
}
func (i *Info) batchWorker() int {
if i.BatchWorker <= 0 {
return 1
}
return i.BatchWorker
}
func (i *Info) batchSize() int {
if i.BatchSize <= 0 {
return 1
}
return i.BatchSize
}
func (i *Info) handleWorker() int {
if i.HandleWorker <= 0 {
return 1
}
return i.HandleWorker
}
func (i *Info) chanSize() int {
if i.ChanSize <= 0 {
return 100
}
return i.ChanSize
}
func (i *Info) autoBatchInterval() time.Duration {
if i.AutoBatchInterval < 10 {
return 30 * time.Second
}
return i.AutoBatchInterval
}