Merged in burst-mode (pull request #364)

revid: make burst mode part of revid API

Approved-by: Saxon Milton <saxon.milton@gmail.com>
This commit is contained in:
Scott Barnard 2020-01-31 04:19:47 +00:00 committed by Saxon Milton
commit 9b8f0dc887
2 changed files with 18 additions and 20 deletions

View File

@ -54,7 +54,6 @@ USAGE
package main package main
import ( import (
"fmt"
"io" "io"
"os" "os"
"runtime/pprof" "runtime/pprof"
@ -199,7 +198,7 @@ func run(rv *revid.Revid, ns *netsender.Sender, l *logger.Logger, nl *netlogger.
continue continue
} }
case modeBurst: case modeBurst:
err = burst(l, rv, ns) err = rv.Burst()
if err != nil { if err != nil {
l.Log(logger.Warning, pkg+"could not start burst", "error", err.Error()) l.Log(logger.Warning, pkg+"could not start burst", "error", err.Error())
ns.SetMode(modePaused, &vs) ns.SetMode(modePaused, &vs)
@ -254,21 +253,3 @@ func readPin(rv *revid.Revid) func(pin *netsender.Pin) error {
return nil return nil
} }
} }
// burst starts revid, waits for time specified in the Config.BurstPeriod
// field, and then stops revid.
//
// TODO: move this functionality to the revid API into a Revid.Burst(time) method.
func burst(l *logger.Logger, r *revid.Revid, s *netsender.Sender) error {
l.Log(logger.Info, pkg+"starting burst")
err := r.Start()
if err != nil {
return fmt.Errorf("could not start revid: %w", err)
}
time.Sleep(time.Duration(r.Config().BurstPeriod) * time.Second)
l.Log(logger.Info, pkg+"stopping burst")
r.Stop()
return nil
}

View File

@ -492,6 +492,23 @@ func (r *Revid) Stop() {
r.running = false r.running = false
} }
// Burst starts revid, waits for time specified, and then stops revid.
func (r *Revid) Burst() error {
r.cfg.Logger.Log(logger.Info, pkg+"starting burst")
err := r.Start()
if err != nil {
return fmt.Errorf("could not start revid: %w", err)
}
dur := time.Duration(r.cfg.BurstPeriod) * time.Second
time.Sleep(dur)
r.cfg.Logger.Log(logger.Info, pkg+"stopping burst")
r.Stop()
return nil
}
func (r *Revid) IsRunning() bool { func (r *Revid) IsRunning() bool {
r.mu.Lock() r.mu.Lock()
defer r.mu.Unlock() defer r.mu.Unlock()