mostly formatting

This commit is contained in:
farhan 2020-11-01 01:59:32 -04:00
parent bef25c73f5
commit a13b29d957
2 changed files with 24 additions and 11 deletions

View File

@ -109,9 +109,21 @@ func main() {
case "add": case "add":
fmt.Println("Add instance") fmt.Println("Add instance")
case "status": case "status":
fmt.Println("Status:" + responseback.Message) for _, runninginstance := range responseback.RunningInstances {
for x, runninginstance := range responseback.RunningInstances { if runninginstance.Status == 0 {
fmt.Println("ID:", x, runninginstance.Endpoint, runninginstance.Status, runninginstance.LastRun) fmt.Fprintf(os.Stdout, "New\t")
} else if runninginstance.Status == 200 {
fmt.Fprintf(os.Stdout, "Running\t")
} else if runninginstance.Status == 602 {
fmt.Fprintf(os.Stdout, "BadInstance")
} else {
fmt.Fprintf(os.Stdout, "%d\t", runninginstance.Status)
}
fmt.Fprintf(os.Stdout, "\t%s\t", runninginstance.LastRun)
if runninginstance.LastRun == "Queued" {
fmt.Fprintf(os.Stdout, "\t\t")
}
fmt.Fprintf(os.Stdout, "%s\n", runninginstance.Endpoint)
} }
} }
} }

View File

@ -21,14 +21,14 @@ import (
) )
const ( const (
INSTANCE_ERROR = -1
NEW_INSTANCE = 0 NEW_INSTANCE = 0
RUNNING = 200 RUNNING = 200
TOOMANYREQUESTS = 429 TOOMANYREQUESTS = 429
CLIENT_ISSUE = 600 CLIENT_ISSUE = 600
ONION_PROTOCOL = 601 ONION_PROTOCOL = 601
UNMARSHAL_ERROR = 602 BAD_RESPONSE = 602
NO_CONNECTION = 603 NO_CONNECTION = 603
BAD_NODEINFO = 604
) )
// Parsing Unmarshal JSON type // Parsing Unmarshal JSON type
@ -121,7 +121,7 @@ func handleClient(commandClient net.Conn, runninginstances *[]RunningInstance, i
case "status": case "status":
responseback.Message = "Ok" responseback.Message = "Ok"
case "add": case "add":
fmt.Println("Add instance: " + commandmap.Endpoint) log.Print("Manually added instance: " + commandmap.Endpoint)
var q InstanceReport var q InstanceReport
q.endpoint = commandmap.Endpoint q.endpoint = commandmap.Endpoint
q.status = NEW_INSTANCE q.status = NEW_INSTANCE
@ -204,7 +204,7 @@ func StartInstancePoll(instancereport InstanceReport, reportPostChan chan Report
err = json.Unmarshal(body, &newposts) err = json.Unmarshal(body, &newposts)
if err != nil { if err != nil {
// instanceReportChan <- InstanceReport{instancereport.endpoint, resp.StatusCode, "", 0} // instanceReportChan <- InstanceReport{instancereport.endpoint, resp.StatusCode, "", 0}
instanceReportChan <- InstanceReport{instancereport.endpoint, 999, "", 0} instanceReportChan <- InstanceReport{instancereport.endpoint, BAD_RESPONSE, "", 0}
return return
} }
@ -340,13 +340,13 @@ func NewInstance(endpoint string, runninginstances *[]RunningInstance, instanceR
go func() { go func() {
var q InstanceReport var q InstanceReport
q.endpoint = endpoint q.endpoint = endpoint
q.status = INSTANCE_ERROR q.status = BAD_NODEINFO
instanceReportChan <- q instanceReportChan <- q
return return
}() }()
} }
newinstance := RunningInstance{endpoint, "", "", NEW_INSTANCE, "QUEUED"} newinstance := RunningInstance{endpoint, "", "", NEW_INSTANCE, "Queued"}
*runninginstances = append(*runninginstances, newinstance) *runninginstances = append(*runninginstances, newinstance)
if nodeinfo.Software.Name == "pleroma" || nodeinfo.Software.Name == "mastodon" { if nodeinfo.Software.Name == "pleroma" || nodeinfo.Software.Name == "mastodon" {
@ -385,7 +385,7 @@ func writePost(pool *pgxpool.Pool, reportpost ReportPost) {
fmt.Println("Account URL: ", reportpost.Account.Url) fmt.Println("Account URL: ", reportpost.Account.Url)
fmt.Println(reportpost) fmt.Println(reportpost)
fmt.Println("--------------------------") fmt.Println("--------------------------")
os.Exit(1) // For now I want this to die and learn why it failed // os.Exit(1) // For now I want this to die and learn why it failed
return return
} }
@ -402,7 +402,7 @@ func writePost(pool *pgxpool.Pool, reportpost ReportPost) {
fmt.Println("account_id", accountid) fmt.Println("account_id", accountid)
fmt.Println("posthash: ", reportpost.posthash) fmt.Println("posthash: ", reportpost.posthash)
fmt.Println("--------------------------") fmt.Println("--------------------------")
os.Exit(1) // For now I want this to die and learn why it failed // os.Exit(1) // For now I want this to die and learn why it failed
return return
} }
} }
@ -411,6 +411,7 @@ func SuspendInstance(suspendinstance InstanceReport, runninginstances *[]Running
for i, runninginstance := range *runninginstances { for i, runninginstance := range *runninginstances {
if runninginstance.Endpoint == suspendinstance.endpoint { if runninginstance.Endpoint == suspendinstance.endpoint {
(*runninginstances)[i].Status = suspendinstance.status (*runninginstances)[i].Status = suspendinstance.status
(*runninginstances)[i].LastRun = time.Now().Format("2006.01.02-15:04:05")
return return
} }
} }