From 77d4ca304d74bbdb60d6178055383a535d7b1e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fikr=C4=81n=20Mutas=C4=81=27il?= <496890-khanzf@users.noreply.gitlab.com> Date: Thu, 16 Dec 2021 04:22:48 +0000 Subject: [PATCH] Added in a staggered start of new instances --- fedilogue/fedilogue.go | 6 ++++-- fedilogue/instance.go | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/fedilogue/fedilogue.go b/fedilogue/fedilogue.go index 3baf6af..702797b 100644 --- a/fedilogue/fedilogue.go +++ b/fedilogue/fedilogue.go @@ -82,6 +82,7 @@ func main() { removeHTMLReg = regexp.MustCompile(`<\/?\s*br\s*>`) re = regexp.MustCompile("^https?://([^/]*)/(.*)$") matchurl = regexp.MustCompile("http?s://[\\w\\-]+\\.[\\w\\-]+\\S*") + staggeredStartChan = make(chan bool) // Start instances located in database rows, err := pool.Query(context.Background(), "SELECT endpoint FROM instances") @@ -91,6 +92,9 @@ func main() { } defer rows.Close() + go staggeredStart(); + go statusReportHandler() + for rows.Next() { var endpoint string err = rows.Scan(&endpoint) @@ -100,14 +104,12 @@ func main() { } _, exists := GetRunner(endpoint) if exists == false { - logInfo("Autostarting " + endpoint) go StartInstance(endpoint) } } go startctl() //go webmain() - go statusReportHandler() runtime.Goexit() } diff --git a/fedilogue/instance.go b/fedilogue/instance.go index 1b69116..ebc2b48 100644 --- a/fedilogue/instance.go +++ b/fedilogue/instance.go @@ -14,6 +14,8 @@ import ( "fmt" ) +var staggeredStartChan chan bool + func DoTries(o *RunningInstance, req *http.Request) (*http.Response, error) { var resp *http.Response var err error @@ -212,8 +214,17 @@ func CheckInstance(newinstance string, callerEndpoint string) { } } +func staggeredStart() { + for { + _ :<- staggeredStartChan + time.Sleep(500 * time.Millisecond) + } +} func StartInstance(endpoint string) { + staggeredStartChan <- true + logInfo("Starting " + endpoint) + // Check if exists. If so, get the object. If not, create it o, _ := GetRunner(endpoint)