Refactoring for testing

This commit is contained in:
Farhan Khan 2021-08-07 19:46:35 +00:00
parent 4a3b5379b9
commit b231629e37

View File

@ -7,6 +7,7 @@ import (
"runtime" "runtime"
"sync" "sync"
"time" "time"
"github.com/microcosm-cc/bluemonday" "github.com/microcosm-cc/bluemonday"
) )
@ -19,39 +20,43 @@ func startpprof() {
logFatal.Fatal(http.ListenAndServe("127.0.0.1:7777", nil)) logFatal.Fatal(http.ListenAndServe("127.0.0.1:7777", nil))
} }
func statusReport() { func statusReportHandler() {
for { for {
running := 0 StatusReport()
keepalive := 0 time.Sleep(time.Second * 60)
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)
} }
} }
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() { func main() {
// Initial Setup // Initial Setup
logInit() logInit()
@ -83,7 +88,7 @@ func main() {
go startctl() go startctl()
//go webmain() //go webmain()
go statusReport() go statusReportHandler()
runtime.Goexit() runtime.Goexit()
} }