diff --git a/engine/headers.go b/engine/headers.go index 267cfd6..437f21f 100644 --- a/engine/headers.go +++ b/engine/headers.go @@ -14,6 +14,7 @@ const ( BAD_RESPONSE = 602 BAD_NODEINFO = 604 UNSUPPORTED_INSTANCE = 605 + STREAM_ENDED = 606 ) // Parsing Unmarshal JSON type @@ -43,9 +44,9 @@ type AccountType struct { // Instance's new min_id value type RunningInstance struct { Software string `json:"software"` - Min_id string Status int `json:"status"` LastRun string `json:"lastrun"` + CaptureType string `json:"capturetype"` } type NodeInfoSoftware struct { diff --git a/engine/instance.go b/engine/instance.go index a454d95..6fb773e 100644 --- a/engine/instance.go +++ b/engine/instance.go @@ -74,7 +74,7 @@ func GetNodeInfo(endpoint string) (NodeInfo) { func StartInstance(endpoint string, reportPostChan chan ReportPost) { nodeinfo := GetNodeInfo(endpoint) if nodeinfo.Software.Name == "" { - var m = runninginstances[endpoint] + m := runninginstances[endpoint] m.Software = "" m.LastRun = time.Now().Format(time.RFC3339) m.Status = UNSUPPORTED_INSTANCE @@ -84,11 +84,19 @@ func StartInstance(endpoint string, reportPostChan chan ReportPost) { return } + ri_mutex.Lock() + m := runninginstances[endpoint] if nodeinfo.Software.Name == "pleroma" { log.Print("Starting " + endpoint + " as " + nodeinfo.Software.Name) + m.CaptureType = "Poll" + runninginstances[endpoint] = m + ri_mutex.Unlock() PollMastodonPleroma(endpoint, reportPostChan) } else if nodeinfo.Software.Name == "mastodon" { log.Print("Starting " + endpoint + " as " + nodeinfo.Software.Name) + m.CaptureType = "Stream" + runninginstances[endpoint] = m + ri_mutex.Unlock() StreamMastodon(endpoint, reportPostChan) } diff --git a/engine/stream.go b/engine/stream.go index 60e31ab..41f74b6 100644 --- a/engine/stream.go +++ b/engine/stream.go @@ -14,9 +14,7 @@ import ( func StreamMastodon(endpoint string, reportPostChan chan ReportPost) { http_client := http.Client{} -// use_auth := false -// var last_refresh int64 var client_id string var client_secret string var oauthData OAuth @@ -60,6 +58,13 @@ func StreamMastodon(endpoint string, reportPostChan chan ReportPost) { } defer resp.Body.Close() + ri_mutex.Lock() + m := runninginstances[endpoint] + m.Status = RUNNING + runninginstances[endpoint] = m + m.LastRun = "Streaming" + ri_mutex.Unlock() + s := bufio.NewScanner(resp.Body) var name string for s.Scan() { @@ -144,4 +149,10 @@ func StreamMastodon(endpoint string, reportPostChan chan ReportPost) { ri_mutex.Unlock() } } + + ri_mutex.Lock() + m.Status = STREAM_ENDED + runninginstances[endpoint] = m + m.LastRun = time.Now().Format(time.RFC3339) + ri_mutex.Unlock() }