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