revid-cli: correctly using ns.Mode() and ns.SetMode()

This commit is contained in:
saxon 2019-02-04 13:25:37 +10:30
parent 6171c4e999
commit ee7eb84d26
2 changed files with 41 additions and 36 deletions

View File

@ -266,18 +266,30 @@ func run(cfg revid.Config) error {
log.Log(logger.Fatal, pkg+"could not initialise revid", "error", err.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 { if err = rv.Update(vars); err != nil {
return err 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 { for {
if err := send(&ns, rv); err != nil { if err := ns.Run(); err != nil {
log.Log(logger.Error, pkg+"polling failed", "error", err.Error()) log.Log(logger.Error, pkg+"Run Failed. Retrying...")
time.Sleep(netSendRetryTime) time.Sleep(netSendRetryTime)
continue continue
} }
if vs != ns.VarSum() { // If var sum hasn't change we continue
if vs == ns.VarSum() {
continue
}
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())
@ -286,32 +298,25 @@ func run(cfg revid.Config) error {
} }
vs = ns.VarSum() vs = ns.VarSum()
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 { if err = rv.Update(vars); err != nil {
return err return err
} }
ns.SetMode(normal)
switch ns.Mode() {
case paused:
case normal:
if err = rv.Start(); err != nil {
return err
}
case burst: case burst:
if err = rv.Start(); err != nil { if err = rv.Start(); err != nil {
return err return err
} }
ns.SetMode(burst) time.Sleep(time.Duration(rv.Config().BurstPeriod))
time.Sleep(rv.Config().BurstPeriod)
if err = rv.Stop(); err != nil { if err = rv.Stop(); err != nil {
return err return err
} }
ns.SetMode(paused) ns.SetMode(paused, &vs)
}
} }
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

@ -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 // outputClips takes the clips produced in the packClips method and outputs them