From a13b29d957f6a39598df5157c081561bd657704d Mon Sep 17 00:00:00 2001 From: Farhan Khan Date: Sun, 1 Nov 2020 01:59:32 -0400 Subject: [PATCH] mostly formatting --- client/searchctl.go | 18 +++++++++++++++--- poll/engine.go | 17 +++++++++-------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/client/searchctl.go b/client/searchctl.go index a421ad7..c237cab 100644 --- a/client/searchctl.go +++ b/client/searchctl.go @@ -109,9 +109,21 @@ func main() { case "add": fmt.Println("Add instance") case "status": - fmt.Println("Status:" + responseback.Message) - for x, runninginstance := range responseback.RunningInstances { - fmt.Println("ID:", x, runninginstance.Endpoint, runninginstance.Status, runninginstance.LastRun) + for _, runninginstance := range responseback.RunningInstances { + if runninginstance.Status == 0 { + 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) } } } diff --git a/poll/engine.go b/poll/engine.go index d4ada34..cc7806a 100644 --- a/poll/engine.go +++ b/poll/engine.go @@ -21,14 +21,14 @@ import ( ) const ( - INSTANCE_ERROR = -1 NEW_INSTANCE = 0 RUNNING = 200 TOOMANYREQUESTS = 429 CLIENT_ISSUE = 600 ONION_PROTOCOL = 601 - UNMARSHAL_ERROR = 602 + BAD_RESPONSE = 602 NO_CONNECTION = 603 + BAD_NODEINFO = 604 ) // Parsing Unmarshal JSON type @@ -121,7 +121,7 @@ func handleClient(commandClient net.Conn, runninginstances *[]RunningInstance, i case "status": responseback.Message = "Ok" case "add": - fmt.Println("Add instance: " + commandmap.Endpoint) + log.Print("Manually added instance: " + commandmap.Endpoint) var q InstanceReport q.endpoint = commandmap.Endpoint q.status = NEW_INSTANCE @@ -204,7 +204,7 @@ func StartInstancePoll(instancereport InstanceReport, reportPostChan chan Report err = json.Unmarshal(body, &newposts) if err != nil { // instanceReportChan <- InstanceReport{instancereport.endpoint, resp.StatusCode, "", 0} - instanceReportChan <- InstanceReport{instancereport.endpoint, 999, "", 0} + instanceReportChan <- InstanceReport{instancereport.endpoint, BAD_RESPONSE, "", 0} return } @@ -340,13 +340,13 @@ func NewInstance(endpoint string, runninginstances *[]RunningInstance, instanceR go func() { var q InstanceReport q.endpoint = endpoint - q.status = INSTANCE_ERROR + q.status = BAD_NODEINFO instanceReportChan <- q return }() } - newinstance := RunningInstance{endpoint, "", "", NEW_INSTANCE, "QUEUED"} + newinstance := RunningInstance{endpoint, "", "", NEW_INSTANCE, "Queued"} *runninginstances = append(*runninginstances, newinstance) 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(reportpost) 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 } @@ -402,7 +402,7 @@ func writePost(pool *pgxpool.Pool, reportpost ReportPost) { fmt.Println("account_id", accountid) fmt.Println("posthash: ", reportpost.posthash) 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 } } @@ -411,6 +411,7 @@ func SuspendInstance(suspendinstance InstanceReport, runninginstances *[]Running for i, runninginstance := range *runninginstances { if runninginstance.Endpoint == suspendinstance.endpoint { (*runninginstances)[i].Status = suspendinstance.status + (*runninginstances)[i].LastRun = time.Now().Format("2006.01.02-15:04:05") return } }