mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
pull out pingUntil function
This commit is contained in:
parent
f2686d02b0
commit
e257f6e8f6
|
@ -666,16 +666,20 @@ func openURL(url string) error {
|
|||
return cmd.Start()
|
||||
}
|
||||
|
||||
func pingAndOpenURL(ctx context.Context, baseURL string) {
|
||||
func pingUntil(ctx context.Context, baseURL string, callback func()) {
|
||||
pingURL := baseURL + "/api/ping"
|
||||
setupURL := baseURL + "/setup"
|
||||
timeout := time.NewTimer(time.Minute)
|
||||
|
||||
ticker := time.NewTimer(time.Second)
|
||||
ticker := time.NewTicker(time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
|
||||
case <-timeout.C:
|
||||
logrus.Warnf("ping hits 1 minute timeout")
|
||||
return
|
||||
|
||||
case <-ctx.Done():
|
||||
return
|
||||
|
||||
|
@ -683,11 +687,18 @@ func pingAndOpenURL(ctx context.Context, baseURL string) {
|
|||
var response map[string]interface{}
|
||||
var err = getJSON(pingURL, &response)
|
||||
if err == nil {
|
||||
if err := openURL(setupURL); err != nil {
|
||||
logrus.WithError(err).Errorf("can not call open command to open the web page")
|
||||
}
|
||||
go callback()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func pingAndOpenURL(ctx context.Context, baseURL string) {
|
||||
setupURL := baseURL + "/setup"
|
||||
go pingUntil(ctx, baseURL, func() {
|
||||
if err := openURL(setupURL); err != nil {
|
||||
logrus.WithError(err).Errorf("can not call open command to open the web page")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user