diff options
-rw-r--r-- | common/cooldown.go | 18 | ||||
-rw-r--r-- | recording/runner.go | 4 |
2 files changed, 22 insertions, 0 deletions
diff --git a/common/cooldown.go b/common/cooldown.go new file mode 100644 index 0000000..75da6fd --- /dev/null +++ b/common/cooldown.go @@ -0,0 +1,18 @@ +package common + +import "time" + +type CoolDown struct { + MinInterval time.Duration + lastTicked time.Time +} + +func (c *CoolDown) Tick() { + defer func() { + c.lastTicked = time.Now() + }() + if c.lastTicked.IsZero() { + return + } + time.Sleep(time.Now().Sub(c.lastTicked)) +} diff --git a/recording/runner.go b/recording/runner.go index f12e9cd..e401eb0 100644 --- a/recording/runner.go +++ b/recording/runner.go @@ -115,6 +115,9 @@ func tryRunTask(t *RunningTask) error { var err error defer wg.Done() run := true + cd := common.CoolDown{ + MinInterval: time.Second * 10, + } loop: for run { err = watch( @@ -150,6 +153,7 @@ func tryRunTask(t *RunningTask) error { } if run { t.logger.Info("Restarting watcher...") + cd.Tick() } else { t.logger.Error("Cannot restart watcher to recover from that error.") } |