@@ -3,17 +3,16 @@ package envsetup
33import (
44 "encoding/json"
55 "fmt"
6+ "github.com/pkg/browser"
67 "net/http"
78 "net/url"
89 "strings"
910 "time"
1011
11- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
12- "github.com/pkg/browser"
13-
1412 "github.com/google/uuid"
1513 "github.com/jfrog/jfrog-cli-core/v2/common/commands"
1614 "github.com/jfrog/jfrog-cli-core/v2/utils/config"
15+ "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
1716 "github.com/jfrog/jfrog-client-go/http/httpclient"
1817 clientutils "github.com/jfrog/jfrog-client-go/utils"
1918 "github.com/jfrog/jfrog-client-go/utils/errorutils"
@@ -25,7 +24,7 @@ import (
2524const (
2625 myJfrogEndPoint = "https://myjfrog-api.jfrog.com/api/v1/activation/cloud/cli/getStatus/"
2726 syncSleepInterval = 5 * time .Second // 5 seconds
28- maxWaitMinutes = 10 * time .Minute // 10 minutes
27+ maxWaitMinutes = 30 * time .Minute // 30 minutes
2928)
3029
3130type EnvSetupCommand struct {
@@ -66,12 +65,13 @@ func (ftc *EnvSetupCommand) Run() (err error) {
6665 return err
6766 }
6867 message :=
69- coreutils .PrintBold ("Your new JFrog environment is ready!" ) +
70- "\n " +
68+ coreutils .PrintBold ("Your new JFrog environment is ready!" ) + "\n " +
7169 "1. CD into your code project directory\n " +
7270 "2. Run \" jf project init\" \n " +
7371 "3. Read more about how to get started at -\n " +
74- coreutils .PrintLink (coreutils .GettingStartedGuideUrl )
72+ coreutils .PrintLink (coreutils .GettingStartedGuideUrl ) +
73+ "\n \n " +
74+ coreutils .GetFeedbackMessage ()
7575
7676 err = coreutils .PrintTable ("" , "" , message )
7777 return
@@ -96,31 +96,51 @@ func (ftc *EnvSetupCommand) getNewServerDetails() (serverDetails *config.ServerD
9696 if err != nil {
9797 return nil , err
9898 }
99- message := fmt .Sprintf ("Sync: Get MyJFrog status report. Request ID:%s..." , ftc .id )
10099
100+ // Define the MyJFrog polling logic.
101+ pollingMessage := fmt .Sprintf ("Sync: Get MyJFrog status report. Request ID:%s..." , ftc .id )
102+ pollingErrorMessage := "Sync: Get MyJFrog status request failed. Attempt: %d. Error: %s"
103+ // The max consecutive polling errors allowed, before completely failing the setup action.
104+ const maxConsecutiveErrors = 6
105+ errorsCount := 0
101106 pollingAction := func () (shouldStop bool , responseBody []byte , err error ) {
102- log .Debug (message )
107+ log .Debug (pollingMessage )
108+ // Send request to MyJFrog.
103109 resp , body , err := client .SendPost (myJfrogEndPoint , requestContent , httpClientDetails , "" )
110+ // If an HTTP error occured.
104111 if err != nil {
105- return true , nil , err
112+ errorsCount ++
113+ log .Debug (fmt .Sprintf (pollingErrorMessage , errorsCount , err .Error ()))
114+ if errorsCount == maxConsecutiveErrors {
115+ return true , nil , err
116+ }
117+ return false , nil , nil
106118 }
119+ // If the response is not the expected 200 or 404.
107120 if err = errorutils .CheckResponseStatus (resp , http .StatusOK , http .StatusNotFound ); err != nil {
108121 err = errorutils .CheckError (errorutils .GenerateResponseError (resp .Status , clientutils .IndentJson (body )))
109- return true , nil , err
122+ errorsCount ++
123+ log .Debug (fmt .Sprintf (pollingErrorMessage , errorsCount , err .Error ()))
124+ if errorsCount == maxConsecutiveErrors {
125+ return true , nil , err
126+ }
127+ return false , nil , nil
110128 }
111- log .Debug (message )
129+ errorsCount = 0
130+
112131 // Wait for 'ready=true' response from MyJFrog
113132 if resp .StatusCode == http .StatusOK {
114133 ftc .progress .SetHeadlineMsg ("Ready for your DevOps journey? Please hang on while we create your environment" )
115134 statusResponse := myJfrogGetStatusResponse {}
116135 if err = json .Unmarshal (body , & statusResponse ); err != nil {
117136 return true , nil , err
118137 }
119- // Got the new server deatiles
138+ // Got the new server details
120139 if statusResponse .Ready {
121140 return true , body , nil
122141 }
123142 }
143+ // The expected 404 response.
124144 return false , nil , nil
125145 }
126146
0 commit comments