pull out ping interval parameter

This commit is contained in:
c9s 2021-02-21 18:58:25 +08:00
parent 3629a1f5a2
commit f2978fa89c
2 changed files with 5 additions and 4 deletions

View File

@ -7,6 +7,7 @@ import (
"os/signal"
"path/filepath"
"runtime"
time2 "time"
"github.com/joho/godotenv"
"github.com/zserge/lorca"
@ -135,7 +136,7 @@ func main() {
}()
log.Infof("pinging the server at %s", baseURL)
server.PingUntil(ctx, baseURL, func() {
server.PingUntil(ctx, time2.Second, baseURL, func() {
log.Infof("got pong, loading base url %s to ui...", baseURL)
if err := ui.Load(baseURL); err != nil {

View File

@ -7,11 +7,11 @@ import (
"github.com/sirupsen/logrus"
)
func PingUntil(ctx context.Context, baseURL string, callback func()) {
func PingUntil(ctx context.Context, interval time.Duration, baseURL string, callback func()) {
pingURL := baseURL + "/api/ping"
timeout := time.NewTimer(3 * time.Minute)
ticker := time.NewTicker(time.Second)
ticker := time.NewTicker(interval)
defer ticker.Stop()
for {
@ -37,7 +37,7 @@ func PingUntil(ctx context.Context, baseURL string, callback func()) {
func pingAndOpenURL(ctx context.Context, baseURL string) {
setupURL := baseURL + "/setup"
go PingUntil(ctx, baseURL, func() {
go PingUntil(ctx, time.Second, baseURL, func() {
if err := openURL(setupURL); err != nil {
logrus.WithError(err).Errorf("can not call open command to open the web page")
}