add delay after error while watching change fix

This commit is contained in:
yusing 2024-03-12 20:33:59 +00:00
parent 0aef8f2931
commit a0f890fed7
4 changed files with 4 additions and 11 deletions

Binary file not shown.

View file

@ -5,6 +5,7 @@ import (
"net/http"
"reflect"
"strings"
"time"
"github.com/docker/cli/cli/connhelper"
"github.com/docker/docker/api/types"
@ -197,6 +198,7 @@ func (p *Provider) grWatchDockerChanges() {
p.BuildStartRoutes()
case err := <-errChan:
p.Logf("Event", "error %s", err)
time.Sleep(100 * time.Millisecond)
msgChan, errChan = p.dockerClient.Events(context.Background(), types.EventsOptions{Filters: filter})
}
}

View file

@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"time"
"github.com/fsnotify/fsnotify"
"gopkg.in/yaml.v3"
@ -69,6 +70,7 @@ func (p *Provider) grWatchFileChanges() {
p.StopAllRoutes()
}
case err := <-watcher.Errors:
time.Sleep(100 * time.Millisecond)
p.Errorf("Watcher", "File watcher error: %s", p.name, err)
}
}

View file

@ -3,7 +3,6 @@ package main
import (
"fmt"
"sync"
"time"
"github.com/docker/docker/client"
"github.com/golang/glog"
@ -18,7 +17,6 @@ type Provider struct {
routes map[string]Route // id -> Route
dockerClient *client.Client
mutex sync.Mutex
lastUpdate time.Time
}
func (p *Provider) GetProxyConfigs() ([]*ProxyConfig, error) {
@ -33,10 +31,6 @@ func (p *Provider) GetProxyConfigs() ([]*ProxyConfig, error) {
}
}
func (p *Provider) needUpdate() bool {
return p.lastUpdate.Add(1 * time.Second).Before(time.Now())
}
func (p *Provider) StopAllRoutes() {
p.mutex.Lock()
defer p.mutex.Unlock()
@ -69,11 +63,6 @@ func (p *Provider) BuildStartRoutes() {
p.mutex.Lock()
defer p.mutex.Unlock()
if !p.needUpdate() {
return
}
p.lastUpdate = time.Now()
p.routes = make(map[string]Route)
cfgs, err := p.GetProxyConfigs()