diff --git a/poll/instance.go b/poll/instance.go index 1f63e40..c7e3a08 100644 --- a/poll/instance.go +++ b/poll/instance.go @@ -28,7 +28,7 @@ func DeferPollRun(instancereport InstanceReport, runninginstances *[]RunningInst } time.Sleep(time.Second * time.Duration(delay)) - go StartInstancePoll(instancereport, reportPostChan, instanceReportChan) + StartInstancePoll(instancereport, reportPostChan, instanceReportChan) } func StartInstancePoll(instancereport InstanceReport, reportPostChan chan ReportPost, instanceReportChan chan InstanceReport) { @@ -45,10 +45,10 @@ func StartInstancePoll(instancereport InstanceReport, reportPostChan chan Report api_timeline := "https://" + instancereport.endpoint + "/api/v1/timelines/public?limit=40&min_id=" + instancereport.min_id resp, err := http.Get(api_timeline) if err != nil { - defer resp.Body.Close() instanceReportChan <- InstanceReport{instancereport.endpoint, CLIENT_ISSUE, "", 0} return } + defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { instanceReportChan <- InstanceReport{instancereport.endpoint, BAD_RESPONSE, "", 0} @@ -117,9 +117,9 @@ func GetNodeInfo(endpoint string, nodeinfo *NodeInfo) { http_client := http.Client{Timeout: 5 * time.Second} resp, err := http_client.Get(api_nodeinfo) if err != nil { - defer resp.Body.Close() return } + defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) err = json.Unmarshal(body, &nodeinfo) diff --git a/poll/main.go b/poll/main.go index b177c63..bff43b1 100644 --- a/poll/main.go +++ b/poll/main.go @@ -73,8 +73,8 @@ func engine() { runninginstances := make([]RunningInstance, 0) // Initial Setup - reportPostChan := make(chan ReportPost, 2000) - instanceReportChan := make(chan InstanceReport, 20) + reportPostChan := make(chan ReportPost) + instanceReportChan := make(chan InstanceReport, 200) // Setup Database pool, err := pgxpool.Connect(context.Background(), "postgres://postgres@127.0.0.1/fedilogue") @@ -106,15 +106,25 @@ func engine() { } }(l) + go func() { + for{ + v := <-reportPostChan // New Post + fmt.Println(v) + go writePost(pool, v) + } + }() + + go func() { + for { + c := <-commandClient // New client connection + go handleClient(c, &runninginstances, instanceReportChan) + } + }() + for { select { - case c := <-commandClient: // New client connection - go handleClient(c, &runninginstances, instanceReportChan) - case v := <-reportPostChan: // New Post - go writePost(pool, v) case w := <-instanceReportChan: // Start or suspend instance if w.status == NEW_INSTANCE { - fmt.Println("The instance: ", x, ", ", len(runninginstances)) x = x + 1 NewInstance(w.endpoint, &runninginstances, instanceReportChan, reportPostChan) } else if w.status == RUNNING || w.status == TOOMANYREQUESTS {