-
Notifications
You must be signed in to change notification settings - Fork 0
/
bulk_common.go
64 lines (54 loc) · 1.08 KB
/
bulk_common.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
package esx
import (
"bytes"
"time"
"go.uber.org/zap"
)
type bulkRespTemp struct {
Errors bool `json:"errors"`
Iterms []struct {
Index struct {
RetInfo struct {
CausedBy map[string]string `json:"caused_by"`
Reason string `json:"reason"`
Type string `json:"type"`
} `json:"error"`
} `json:"index"`
} `json:"items"`
}
type BulkOption struct {
Tid int
MaxCT int
MaxSize int
MaxTime time.Duration
}
type BulkClient struct {
running bool
logger *zap.Logger
tid int
client *Client
ct int
maxCT int
size int
maxSize int
lastTime time.Time
maxTime time.Duration
datas *bytes.Buffer
rawdatas []map[string]string
}
func NewBulkClient(logger *zap.Logger, client *Client, opt BulkOption) *BulkClient {
return &BulkClient{
running: true,
logger: logger,
tid: opt.Tid,
client: client,
ct: 0,
maxCT: opt.MaxCT,
size: 0,
maxSize: opt.MaxSize,
lastTime: time.Now(),
maxTime: opt.MaxTime,
datas: bytes.NewBufferString(""),
rawdatas: make([]map[string]string, 0),
}
}