Skip to content

Commit a8f42be

Browse files
author
施凯伦
committed
add retry
1 parent 81efabd commit a8f42be

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package xiaomipush
33
import (
44
"encoding/json"
55
"errors"
6+
"fmt"
67
"io/ioutil"
78
"net/http"
89
"net/url"
@@ -617,8 +618,15 @@ func (m *MiPush) doPost(url string, form url.Values) ([]byte, error) {
617618
req.Header.Set("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8")
618619
req.Header.Set("Authorization", "key="+m.appSecret)
619620
client := &http.Client{}
621+
tryTime := 0
622+
tryAgain:
620623
resp, err = client.Do(req)
621624
if err != nil {
625+
fmt.Println("xiaomi push post err", err, tryTime)
626+
tryTime += 1
627+
if tryTime < PostRetryTimes {
628+
goto tryAgain
629+
}
622630
return nil, err
623631
}
624632
result, err = m.handleResponse(resp)

constants.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ const (
4545
TopicsAllURL = "/v1/topic/all" // 获取一个应用的某个用户的目前订阅的所有Topic
4646
)
4747

48+
var (
49+
PostRetryTimes = 3
50+
)
51+
4852
// for future targeted push
4953
var (
5054
BrandsMap = map[string]string{

0 commit comments

Comments
 (0)