From ee7eb84d26e29b3d9cab7005fddd48d1847a8211 Mon Sep 17 00:00:00 2001 From: saxon Date: Mon, 4 Feb 2019 13:25:37 +1030 Subject: [PATCH] revid-cli: correctly using ns.Mode() and ns.SetMode() --- cmd/revid-cli/main.go | 75 +++++++++++++++++++++++-------------------- revid/revid.go | 2 +- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 58f8e507..ac8fff12 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -266,52 +266,57 @@ func run(cfg revid.Config) error { log.Log(logger.Fatal, pkg+"could not initialise revid", "error", err.Error()) } + // Update revid to get latest config settings from netreceiver. if err = rv.Update(vars); err != nil { return err } + // If mode on netreceiver isn't paused then we can start revid. + if ns.Mode() != paused { + if err = rv.Start(); err != nil { + return err + } + } + for { - if err := send(&ns, rv); err != nil { - log.Log(logger.Error, pkg+"polling failed", "error", err.Error()) + if err := ns.Run(); err != nil { + log.Log(logger.Error, pkg+"Run Failed. Retrying...") time.Sleep(netSendRetryTime) continue } - if vs != ns.VarSum() { - vars, err := ns.Vars() - if err != nil { - log.Log(logger.Error, pkg+"netSender failed to get vars", "error", err.Error()) - time.Sleep(netSendRetryTime) - continue - } - vs = ns.VarSum() + // If var sum hasn't change we continue + if vs == ns.VarSum() { + continue + } - switch ns.Mode() { - case paused: - if rv.IsRunning() { - log.Log(logger.Info, pkg+"pausing revid") - if err = rv.Stop(); err != nil { - log.Log(logger.Error, pkg+"failed to stop revid", "error", err.Error()) - continue - } - ns.SetMode(paused) - } - case normal: - if err = rv.Update(vars); err != nil { - return err - } - ns.SetMode(normal) - case burst: - if err = rv.Start(); err != nil { - return err - } - ns.SetMode(burst) - time.Sleep(rv.Config().BurstPeriod) - if err = rv.Stop(); err != nil { - return err - } - ns.SetMode(paused) + vars, err := ns.Vars() + if err != nil { + log.Log(logger.Error, pkg+"netSender failed to get vars", "error", err.Error()) + time.Sleep(netSendRetryTime) + continue + } + vs = ns.VarSum() + + if err = rv.Update(vars); err != nil { + return err + } + + switch ns.Mode() { + case paused: + case normal: + if err = rv.Start(); err != nil { + return err } + case burst: + if err = rv.Start(); err != nil { + return err + } + time.Sleep(time.Duration(rv.Config().BurstPeriod)) + if err = rv.Stop(); err != nil { + return err + } + ns.SetMode(paused, &vs) } sleepTime, _ := strconv.Atoi(ns.Param("mp")) time.Sleep(time.Duration(sleepTime) * time.Second) diff --git a/revid/revid.go b/revid/revid.go index 9f1cc12c..e4c7dbbe 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -488,7 +488,7 @@ func (r *Revid) Update(vars map[string]string) error { } } - return r.Start() + return nil } // outputClips takes the clips produced in the packClips method and outputs them