cmd/revid-cli: clean up netsender handling

This commit is contained in:
Dan Kortschak 2018-06-08 22:15:14 +09:30
parent 043ff35dfe
commit f5a3899e1d
1 changed files with 13 additions and 14 deletions
cmd/revid-cli

View File

@ -33,6 +33,7 @@ import (
"fmt"
"os/exec"
"strconv"
"strings"
"time"
"bitbucket.org/ausocean/av/revid"
@ -93,7 +94,6 @@ const (
// Globals
var (
ns netsender.Netsender
revidInst revid.Revid
config revid.Config
)
@ -247,6 +247,7 @@ func main() {
config.Timeout = *configFlags[timeoutPtr]
config.IntraRefreshPeriod = *configFlags[intraRefreshPeriodPtr]
var ns netsender.Netsender
var vs int
if *netSenderFlagPtr {
// initialize NetSender and use NetSender's logger
@ -267,7 +268,7 @@ func main() {
// loop in NetSender mode
for *netSenderFlagPtr {
if err := netSend(); err != nil {
if err := sendTo(ns); err != nil {
config.Logger.Log(progName, "Error", err.Error())
time.Sleep(netSendRetryTime)
continue
@ -305,24 +306,22 @@ func main() {
stopRevid()
}
// netSend implements the NetSender client, and is called every monPeriod seconds.
// It handles NetReceiver configuration and sends requested data to the cloud.
func netSend() error {
// sendTo handles NetReceiver configuration and sends requested data to the cloud.
func sendTo(ns netsender.Netsender) error {
if !ns.IsConfigured() {
if err := ns.Config(); err != nil {
err := ns.Config()
if err != nil {
return err
}
}
inputs := netsender.SplitCSV(ns.GetConfigParam("ip"))
if _, reconfig, err := ns.Send(netsender.RequestPoll, inputs); err != nil {
inputs := strings.Split(ns.GetConfigParam("ip"), ",")
_, reconfig, err := ns.Send(netsender.RequestPoll, inputs)
if err != nil {
return err
} else {
if reconfig {
if err := ns.Config(); err != nil {
return err
}
}
}
if reconfig {
return ns.Config()
}
return nil
}