Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Kelp GUI: start backend server before sending ready string message (c…
Browse files Browse the repository at this point in the history
…loses #381)
  • Loading branch information
nikhilsaraf committed Feb 26, 2020
1 parent c84f113 commit f2d75d5
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions cmd/server_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
bootstrap "github.com/asticode/go-astilectron-bootstrap"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/nikhilsaraf/go-tools/multithreading"
"github.com/rs/cors"
"github.com/spf13/cobra"
"github.com/stellar/go/clients/horizonclient"
Expand All @@ -42,6 +43,7 @@ const ccxtWaitSeconds = 60
const versionPlaceholder = "VERSION_PLACEHOLDER"
const stringPlaceholder = "PLACEHOLDER_URL"
const redirectPlaceholder = "REDIRECT_URL"
const sleepNumSecondsBeforeReadyString = 1
const readyPlaceholder = "READY_STRING"
const readyStringIndicator = "Serving frontend and API server on HTTP port"

Expand Down Expand Up @@ -223,15 +225,28 @@ func init() {
gui.FileServer(r, "/", gui.FS)

portString := fmt.Sprintf(":%d", *options.port)
log.Printf("%s: %d\n", readyStringIndicator, *options.port)
if isLocalMode {
e = http.ListenAndServe(portString, r)
if e != nil {
log.Fatal(e)
log.Printf("starting server on port %d\n", *options.port)

threadTracker := multithreading.MakeThreadTracker()
e = threadTracker.TriggerGoroutine(func(inputs []interface{}) {
if isLocalMode {
e1 := http.ListenAndServe(portString, r)
if e1 != nil {
log.Fatal(e1)
}
} else {
_ = http.ListenAndServe(portString, r)
}
} else {
_ = http.ListenAndServe(portString, r)
}, nil)
if e != nil {
log.Fatal(e)
}

log.Printf("sleeping for %d seconds before showing the ready string indicator...\n", sleepNumSecondsBeforeReadyString)
time.Sleep(sleepNumSecondsBeforeReadyString * time.Second)

log.Printf("%s: %d\n", readyStringIndicator, *options.port)
threadTracker.Wait()
}
}

Expand Down

0 comments on commit f2d75d5

Please sign in to comment.