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,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)

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