From 68b33550dec76ec8b2c32e9b6a1eab07cebf3faf Mon Sep 17 00:00:00 2001 From: zenghur Date: Mon, 18 May 2020 15:16:08 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=87=8F=E5=B0=91err=E6=97=B6?= =?UTF-8?q?=E5=80=99=E7=9A=84=E8=AF=B7=E6=B1=82=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- diamond.go | 12 +++++++----- long_pull.go | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/diamond.go b/diamond.go index 6bf8b95..a900873 100644 --- a/diamond.go +++ b/diamond.go @@ -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" ) @@ -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{ diff --git a/long_pull.go b/long_pull.go index eeaa046..7c13fd9 100644 --- a/long_pull.go +++ b/long_pull.go @@ -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 (