cmd/revid-cli & revid: using goto to sleep for monitor period, and using wg.Done() at the end of output routine.

This commit is contained in:
saxon 2019-02-04 17:12:30 +10:30
parent 93e3899725
commit 8978f9edc5
2 changed files with 8 additions and 3 deletions

View File

@ -253,12 +253,15 @@ func handleFlags() revid.Config {
func run(cfg revid.Config) error { func run(cfg revid.Config) error {
log.Log(logger.Info, pkg+"running in NetSender mode") log.Log(logger.Info, pkg+"running in NetSender mode")
var err error
var vars map[string]string
// initialize NetSender and use NetSender's logger // initialize NetSender and use NetSender's logger
var ns netsender.Sender var ns netsender.Sender
if err := ns.Init(log, nil, nil, nil); err != nil { if err := ns.Init(log, nil, nil, nil); err != nil {
return err return err
} }
vars, _ := ns.Vars() vars, _ = ns.Vars()
vs := ns.VarSum() vs := ns.VarSum()
rv, err := revid.New(cfg, &ns) rv, err := revid.New(cfg, &ns)
@ -291,10 +294,10 @@ func run(cfg revid.Config) error {
// If var sum hasn't change we continue // If var sum hasn't change we continue
if vs == ns.VarSum() { if vs == ns.VarSum() {
continue goto sleep
} }
vars, err := ns.Vars() vars, err = ns.Vars()
if err != nil { if err != nil {
log.Log(logger.Error, pkg+"netSender failed to get vars", "error", err.Error()) log.Log(logger.Error, pkg+"netSender failed to get vars", "error", err.Error())
time.Sleep(netSendRetryTime) time.Sleep(netSendRetryTime)
@ -324,6 +327,7 @@ func run(cfg revid.Config) error {
} }
ns.SetMode(paused, &vs) ns.SetMode(paused, &vs)
} }
sleep:
sleepTime, _ := strconv.Atoi(ns.Param("mp")) sleepTime, _ := strconv.Atoi(ns.Param("mp"))
time.Sleep(time.Duration(sleepTime) * time.Second) time.Sleep(time.Duration(sleepTime) * time.Second)
} }

View File

@ -582,6 +582,7 @@ loop:
r.config.Logger.Log(logger.Error, pkg+"failed to close output"+strconv.Itoa(i)+" destination", "error", err.Error()) r.config.Logger.Log(logger.Error, pkg+"failed to close output"+strconv.Itoa(i)+" destination", "error", err.Error())
} }
} }
r.wg.Done()
} }
// startRaspivid sets up things for input from raspivid i.e. starts // startRaspivid sets up things for input from raspivid i.e. starts