mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 04:42:33 +02:00
add delay after error while watching change fix
This commit is contained in:
parent
0aef8f2931
commit
a0f890fed7
4 changed files with 4 additions and 11 deletions
BIN
bin/go-proxy
BIN
bin/go-proxy
Binary file not shown.
|
@ -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})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Reference in a new issue