Skip to content

Commit 041d5d7

Browse files
authored
Merge pull request #20 from LambdaTest/MLE-17521-new
Mle 17521 new
2 parents ec49116 + 6de02d2 commit 041d5d7

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

localEvaluation/localEvaluation.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var (
1919
LocalEvaluationConfigPollInterval = 120
2020
LocalEvaluationConfigPollerRequestTimeout = 60
2121
LocalEvaluationDeploymentKey = "server-jAqqJaX3l8PgNiJpcv9j20ywPzANQQFh"
22+
retries = 5
2223
)
2324

2425
type Variant struct {
@@ -42,7 +43,7 @@ type UserProperties struct {
4243
TemplateId string `json:"template_id,omitempty"`
4344
}
4445

45-
func init() {
46+
func Init() {
4647
err := godotenv.Load()
4748
if err != nil {
4849
fmt.Printf("No .env file found")
@@ -68,14 +69,24 @@ func init() {
6869
}
6970

7071
func Initialize() {
72+
Init()
7173
config := local.Config{
7274
Debug: LocalEvaluationConfigDebug,
7375
ServerUrl: LocalEvaluationConfigServerUrl,
7476
FlagConfigPollerInterval: time.Duration(LocalEvaluationConfigPollInterval) * time.Second,
7577
FlagConfigPollerRequestTimeout: time.Duration(LocalEvaluationConfigPollerRequestTimeout) * time.Second,
7678
}
7779
client = local.Initialize(LocalEvaluationDeploymentKey, &config)
78-
err := client.Start()
80+
var err error
81+
for i := 0; i < retries; i++ {
82+
err = client.Start()
83+
if err != nil {
84+
err = fmt.Errorf("unable to create local evaluation client with given config %+v attempt:%v with error %s", config, i+1, err.Error())
85+
continue
86+
} else {
87+
break
88+
}
89+
}
7990
if err != nil {
8091
err = fmt.Errorf("unable to create local evaluation client with given config %+v with error %s", config, err.Error())
8192
panic(err)
@@ -84,7 +95,16 @@ func Initialize() {
8495

8596
func InitializeWithConfig(conf local.Config, deploymentKey string) {
8697
client = local.Initialize(deploymentKey, &conf)
87-
err := client.Start()
98+
var err error
99+
for i := 0; i < retries; i++ {
100+
err = client.Start()
101+
if err != nil {
102+
err = fmt.Errorf("unable to create local evaluation client with given config %+v attempt:%v with error %s", conf, i+1, err.Error())
103+
continue
104+
} else {
105+
break
106+
}
107+
}
88108
if err != nil {
89109
err = fmt.Errorf("unable to create local evaluation client with given config %+v with error %s", conf, err.Error())
90110
panic(err)

0 commit comments

Comments
 (0)