From 7a8597fa853409d2c3d6e886bf3130ab1dd23c2e Mon Sep 17 00:00:00 2001 From: luhaoling <2198702716@qq.com> Date: Fri, 2 Feb 2024 16:52:40 +0800 Subject: [PATCH] fix: fix the cycle detection --- pkg/common/db/unrelation/mongo.go | 1 - tools/component/component.go | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/common/db/unrelation/mongo.go b/pkg/common/db/unrelation/mongo.go index fe89c6b8a..d396f80cc 100644 --- a/pkg/common/db/unrelation/mongo.go +++ b/pkg/common/db/unrelation/mongo.go @@ -57,7 +57,6 @@ func NewMongo() (*Mongo, error) { return &Mongo{db: mongoClient}, nil } if shouldRetry(err) { - fmt.Printf("Failed to connect to MongoDB, retrying: %s\n", err) time.Sleep(time.Second) // exponential backoff could be implemented here continue } diff --git a/tools/component/component.go b/tools/component/component.go index 787ca8af6..aebd96b69 100644 --- a/tools/component/component.go +++ b/tools/component/component.go @@ -56,6 +56,7 @@ func initCfg() error { type checkFunc struct { name string function func() error + flag bool } func main() { @@ -87,11 +88,15 @@ func main() { var err error allSuccess := true for _, check := range checks { - err = check.function() + if !check.flag { + err = check.function() + continue + } if err != nil { component.ErrorPrint(fmt.Sprintf("Starting %s failed:%v.", check.name, err)) allSuccess = false } else { + check.flag = true component.SuccessPrint(fmt.Sprintf("%s connected successfully", check.name)) } }