Added in a staggered start of new instances

Reverted exporting the Tag element of activity post
This commit is contained in:
Farhan Khan 2021-12-15 23:18:59 -05:00
parent 387f3210fa
commit f5b9285e44
3 changed files with 17 additions and 4 deletions

View File

@ -82,6 +82,7 @@ func main() {
removeHTMLReg = regexp.MustCompile(`<\/?\s*br\s*>`) removeHTMLReg = regexp.MustCompile(`<\/?\s*br\s*>`)
re = regexp.MustCompile("^https?://([^/]*)/(.*)$") re = regexp.MustCompile("^https?://([^/]*)/(.*)$")
matchurl = regexp.MustCompile("http?s://[\\w\\-]+\\.[\\w\\-]+\\S*") matchurl = regexp.MustCompile("http?s://[\\w\\-]+\\.[\\w\\-]+\\S*")
staggeredStartChan = make(chan bool)
// Start instances located in database // Start instances located in database
rows, err := pool.Query(context.Background(), "SELECT endpoint FROM instances") rows, err := pool.Query(context.Background(), "SELECT endpoint FROM instances")
@ -91,6 +92,9 @@ func main() {
} }
defer rows.Close() defer rows.Close()
go staggeredStart();
go statusReportHandler()
for rows.Next() { for rows.Next() {
var endpoint string var endpoint string
err = rows.Scan(&endpoint) err = rows.Scan(&endpoint)
@ -100,14 +104,12 @@ func main() {
} }
_, exists := GetRunner(endpoint) _, exists := GetRunner(endpoint)
if exists == false { if exists == false {
logInfo("Autostarting " + endpoint)
go StartInstance(endpoint) go StartInstance(endpoint)
} }
} }
go startctl() go startctl()
//go webmain() //go webmain()
go statusReportHandler()
runtime.Goexit() runtime.Goexit()
} }

View File

@ -14,6 +14,8 @@ import (
"fmt" "fmt"
) )
var staggeredStartChan chan bool
func DoTries(o *RunningInstance, req *http.Request) (*http.Response, error) { func DoTries(o *RunningInstance, req *http.Request) (*http.Response, error) {
var resp *http.Response var resp *http.Response
var err error 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) { func StartInstance(endpoint string) {
staggeredStartChan <- true
logInfo("Starting " + endpoint)
// Check if exists. If so, get the object. If not, create it // Check if exists. If so, get the object. If not, create it
o, _ := GetRunner(endpoint) o, _ := GetRunner(endpoint)

View File

@ -64,7 +64,7 @@ type PostJson struct {
Published time.Time `json:"published"` Published time.Time `json:"published"`
Source string `json:"source"` Source string `json:"source"`
Summary string `json:"summary"` Summary string `json:"summary"`
tag []TagType `json:"tag"` Tag []TagType `json:"tag"`
To []string `json:"to"` To []string `json:"to"`
Type string `json:"type"` Type string `json:"type"`
@ -150,7 +150,7 @@ func check_activity(uri string) {
activityjson.normalized = spaceReg.ReplaceAllString(activityjson.normalized, " ") activityjson.normalized = spaceReg.ReplaceAllString(activityjson.normalized, " ")
var hashtags []string var hashtags []string
for _, tag := range activityjson.tag { for _, tag := range activityjson.Tag {
if tag.Type == "Hashtag" { if tag.Type == "Hashtag" {
hashtags = append(hashtags, strings.ToLower(tag.Name)) hashtags = append(hashtags, strings.ToLower(tag.Name))
} }