Skip to content

Commit

Permalink
chore: 减少err时候的请求次数
Browse files Browse the repository at this point in the history
  • Loading branch information
zenghur committed May 18, 2020
1 parent 06d0b4e commit 68b3355
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 7 additions & 5 deletions diamond.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ package aliacm

import (
"fmt"
"math/rand"
"time"

"github.com/xiaojiaoyu100/aliyun-acm/v2/config"
"github.com/xiaojiaoyu100/aliyun-acm/v2/info"
"github.com/xiaojiaoyu100/aliyun-acm/v2/observer"
"github.com/xiaojiaoyu100/curlew"
"github.com/xiaojiaoyu100/roc"
"math/rand"
"time"

"context"

"github.com/sirupsen/logrus"
"github.com/xiaojiaoyu100/cast"
)
Expand Down Expand Up @@ -208,16 +210,16 @@ func (d *Diamond) notify(oo ...*observer.Observer) {
}

func (d *Diamond) hang(i info.Info) {
// 不要在同一时间启动long pull
time.Sleep(time.Duration(randomIntInRange(20, 100)) * time.Millisecond)
go func() {
for {
// 防止网络差的时候没挂住
time.Sleep(time.Duration(randomIntInRange(20, 100)) * time.Millisecond)

content, newContentMD5, err := d.LongPull(i, d.all[i].ContentMD5)
d.checkErr(i, err)

// 防止MD5被重置,重新请求
if newContentMD5 == "" {
time.Sleep(time.Duration(randomIntInRange(1000, 1500)) * time.Millisecond)
continue
}
conf := &config.Config{
Expand Down
3 changes: 2 additions & 1 deletion long_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package aliacm
import (
"context"
"errors"
"github.com/xiaojiaoyu100/aliyun-acm/v2/info"
"net/http"
"net/url"
"strings"

"github.com/xiaojiaoyu100/aliyun-acm/v2/info"
)

const (
Expand Down

0 comments on commit 68b3355

Please sign in to comment.