Skip to content

Commit

Permalink
上传日志失败重试3次
Browse files Browse the repository at this point in the history
  • Loading branch information
dongjunjie committed Feb 8, 2022
1 parent cfa0ff4 commit 36eef02
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions http_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,17 @@ func (h *HttpTransport) flush() {
if h.bufferLength > 1000 {
bytesData, err := json.Marshal(arrStrBufferLog)
if err != nil {
sendLog(1, arrStrBufferLog, "")
sendLog(1, arrStrBufferLog, "", 0)
}
strLog, err := doZlibCompress(bytesData)
if err != nil {
sendLog(1, arrStrBufferLog, "")
sendLog(1, arrStrBufferLog, "", 0)
} else {
sendLog(2, []string{}, strLog)
sendLog(2, []string{}, strLog, 0)
}

} else {
sendLog(1, arrStrBufferLog, "")
sendLog(1, arrStrBufferLog, "", 0)
}

h.bufferLog = h.bufferLog[:0]
Expand All @@ -150,24 +150,33 @@ func (h *HttpTransport) flush() {
}

/**
* @description: 请求接口 上传日志
* @description: 请求接口 上传日志 失败重试3次
* @param {int32} _type
* @param {[]string} data1
* @param {string} data2
* @return {*}
*/
func sendLog(_type int32, data1 []string, data2 string) {
func sendLog(_type int32, data1 []string, data2 string, tryNum int32) {
defer func() {
if err := recover(); err != nil {
data := make(map[string]interface{})
data["type"] = _type
data["data1"] = data1
data["data2"] = data2
bytesData, _ := json.Marshal(data)
if tryNum >= 3 {
data := make(map[string]interface{})
data["type"] = _type
data["data1"] = data1
data["data2"] = data2
bytesData, _ := json.Marshal(data)

httpErrorLog(string(bytesData))
httpErrorLog(string(bytesData))

fmt.Println(err)
} else {
go func() {
time.Sleep(time.Second)
tryNum++
sendLog(_type, data1, data2, tryNum)
}()
}

fmt.Println(err)
}
}()

Expand Down

0 comments on commit 36eef02

Please sign in to comment.