perf: add http request timeout and add request retry

main
zggsong 2 years ago
parent 0caf71193b
commit 07d77c6b26

@ -56,7 +56,7 @@ func Login(userName, passwd string) (string, error) {
// @return []string
//
func Upload2Azure(auth string, images map[string]string) ([]string, error) {
var client = &http.Client{}
var client = &http.Client{Timeout: 10}
uploadUrl := "https://p.luxshare-ict.com/api/Azure/TencentFileToAzure"
contentType := "application/x-www-form-urlencoded"
@ -98,7 +98,7 @@ func Upload2Azure(auth string, images map[string]string) ([]string, error) {
// @return error
//
func EpidemicRegistration(auth string, images []string) error {
var client = &http.Client{}
var client = &http.Client{Timeout: 10}
uploadUrl := "https://m.luxshare-ict.com/api/EpidemicSys/EpidemicRegistration/LVIQuestSave2"
contentType := "application/x-www-form-urlencoded"
@ -177,7 +177,7 @@ func EpidemicRegistration(auth string, images []string) error {
// @return error
//
func RefreshDoor(auth string) error {
var client = &http.Client{}
var client = &http.Client{Timeout: 10}
refreshUrl := "https://m.luxshare-ict.com/api/EpidemicSys/EpidemicRegistration/RefreshDoor"
request, err := http.NewRequest("POST", refreshUrl, nil)

@ -122,25 +122,35 @@ func DeclarationService(files map[string]string) {
}
//申报
if err = core.EpidemicRegistration(ticket, imagesLinks); err != nil {
log.Printf(err.Error())
util.Send(err.Error())
return
for i := 0; i < 3; i++ {
err = core.EpidemicRegistration(ticket, imagesLinks)
if err != nil && i > 1 {
log.Printf("重试3次失败%v", err.Error())
util.Send(err.Error())
return
} else {
break
}
}
log.Printf("[INFO] 每日申报成功")
//等待
time.Sleep(time.Second * 3)
//time.Sleep(time.Second * 3)
//刷新门禁
if err = core.RefreshDoor(ticket); err != nil {
log.Printf(err.Error())
util.Send(err.Error())
return
for i := 0; i < 3; i++ {
err = core.RefreshDoor(ticket)
if err != nil && i > 1 {
log.Printf("重试3次失败%v", err.Error())
util.Send(err.Error())
return
} else {
break
}
}
log.Printf("[INFO] 刷新门禁成功")
util.Send("[INFO] 每日申报成功")
util.Send("[INFO] 每日申报+刷新门禁成功")
}
//

Loading…
Cancel
Save