From b231629e3771a2baf9af9f15d9e2a02838b6de63 Mon Sep 17 00:00:00 2001 From: Farhan Khan Date: Sat, 7 Aug 2021 19:46:35 +0000 Subject: [PATCH] Refactoring for testing --- fedilogue/fedilogue.go | 65 +++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/fedilogue/fedilogue.go b/fedilogue/fedilogue.go index b72d51e..44e66bf 100644 --- a/fedilogue/fedilogue.go +++ b/fedilogue/fedilogue.go @@ -7,6 +7,7 @@ import ( "runtime" "sync" "time" + "github.com/microcosm-cc/bluemonday" ) @@ -19,39 +20,43 @@ func startpprof() { logFatal.Fatal(http.ListenAndServe("127.0.0.1:7777", nil)) } -func statusReport() { +func statusReportHandler() { for { - running := 0 - keepalive := 0 - unsupported := 0 - - mastodon := 0 - pleroma := 0 - other := 0 - ri_mutex.Lock() - for _, o := range runninginstances { - if o.Status == 200 { - running = running + 1 - } else if o.Status == 607 { // Keepalive - keepalive = keepalive + 1 - } else if o.Status == 605 {// Unsupported instance - unsupported = unsupported + 1 - } - - if o.Software == "mastodon" && o.Status == 200 { - mastodon = mastodon + 1 - } else if o.Software == "pleroma" && o.Status == 200 { - pleroma = pleroma + 1 - } else if o.Status == 200 { - other = other + 1 - } - } - ri_mutex.Unlock() - logInfo("Running:",running," Keepalive:", keepalive, " Unsupported:", unsupported, " M:", mastodon, ",P:",pleroma,",O:",other) - time.Sleep(time.Second*60) + StatusReport() + time.Sleep(time.Second * 60) } } +func StatusReport() { + running := 0 + keepalive := 0 + unsupported := 0 + + mastodon := 0 + pleroma := 0 + other := 0 + ri_mutex.Lock() + for _, o := range runninginstances { + if o.Status == 200 { + running = running + 1 + } else if o.Status == 607 { // Keepalive + keepalive = keepalive + 1 + } else if o.Status == 605 { // Unsupported instance + unsupported = unsupported + 1 + } + + if o.Software == "mastodon" && o.Status == 200 { + mastodon = mastodon + 1 + } else if o.Software == "pleroma" && o.Status == 200 { + pleroma = pleroma + 1 + } else if o.Status == 200 { + other = other + 1 + } + } + ri_mutex.Unlock() + logInfo("Running:", running, " Keepalive:", keepalive, " Unsupported:", unsupported, " M:", mastodon, ",P:", pleroma, ",O:", other) +} + func main() { // Initial Setup logInit() @@ -83,7 +88,7 @@ func main() { go startctl() //go webmain() - go statusReport() + go statusReportHandler() runtime.Goexit() }