-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
log2BigDb.go
63 lines (56 loc) · 874 Bytes
/
log2BigDb.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
package go_utils
import (
"log"
"time"
)
// 记录日志到 大数据搜索引擎
func SendEsLog(m1 interface{}) {
if 0 == len(EsUrl) {
return
}
szId := "xxx"
SendReq(&m1, szId, ESaveType(GetVal("toolType")))
}
var bOk = make(chan struct{})
var bDo = make(chan struct{}, 1)
var oR = make(chan interface{}, 5000)
func DoSaves() {
var n = len(oR)
var oS = make([]interface{}, n)
for n > 0 {
oS = append(oS, <-oR)
n--
}
if 0 < len(oS) {
DoSyncFunc(func() {
SendEsLog(&oS)
log.Println("DoSaves", n)
})
}
}
func PushLog(o interface{}) {
oR <- o
}
func DoRunning() {
defer DoSaves()
for {
select {
case <-oR:
if 5000 <= len(oR) {
bDo <- struct{}{}
}
case <-bOk:
return
case <-bDo:
DoSaves()
}
time.Sleep(16 * time.Millisecond)
}
}
func CloseLogBigDb() {
DoSaves()
close(bOk)
defer func() {
close(bDo)
}()
}