Skip to content

Commit

Permalink
retry after watch error
Browse files Browse the repository at this point in the history
  • Loading branch information
HeavyHorst committed Jul 26, 2019
1 parent 38b67b8 commit b25f0bc
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/template/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,22 @@ func (s Backend) watch(ctx context.Context, processChan chan Backend, errChan ch
var lastIndex uint64
keysPrefix := appendPrefix(s.Prefix, s.Keys)

var backendError bool

for {
select {
case <-ctx.Done():
return
default:
if backendError {
processChan <- s
backendError = false
}

index, err := s.WatchPrefix(ctx, s.Prefix, easykv.WithKeys(keysPrefix), easykv.WithWaitIndex(lastIndex))
if err != nil {
if err != easykv.ErrWatchCanceled {
backendError = true
errChan <- berr.BackendError{Message: err.Error(), Backend: s.Name}
time.Sleep(2 * time.Second)
}
Expand Down

0 comments on commit b25f0bc

Please sign in to comment.