Add backend throttle duration, resolves https://github.com/EmileVauge/traefik/issues/46
This commit is contained in:
parent
fd234c683c
commit
46e162e6a9
4 changed files with 64 additions and 16 deletions
29
traefik.go
29
traefik.go
|
@ -59,6 +59,8 @@ func main() {
|
|||
var configurationRouter *mux.Router
|
||||
var configurationChan = make(chan configMessage, 10)
|
||||
defer close(configurationChan)
|
||||
var configurationChanValidated = make(chan configMessage, 10)
|
||||
defer close(configurationChanValidated)
|
||||
var sigs = make(chan os.Signal, 1)
|
||||
defer close(sigs)
|
||||
var stopChan = make(chan bool)
|
||||
|
@ -96,10 +98,33 @@ func main() {
|
|||
|
||||
// listen new configurations from providers
|
||||
go func() {
|
||||
|
||||
lastReceivedConfiguration := time.Unix(0, 0)
|
||||
lastConfigs := make(map[string]*configMessage)
|
||||
for {
|
||||
configMsg := <-configurationChan
|
||||
log.Infof("Configuration receveived from provider %s: %#v", configMsg.providerName, configMsg.configuration)
|
||||
lastConfigs[configMsg.providerName] = &configMsg
|
||||
if time.Now().After(lastReceivedConfiguration.Add(time.Duration(globalConfiguration.BackendsThrottleDuration))) {
|
||||
log.Infof("Last %s config received more than %s, OK", configMsg.providerName, globalConfiguration.BackendsThrottleDuration)
|
||||
// last config received more than n s ago
|
||||
configurationChanValidated <- configMsg
|
||||
} else {
|
||||
log.Infof("Last %s config received less than %s, waiting...", configMsg.providerName, globalConfiguration.BackendsThrottleDuration)
|
||||
go func() {
|
||||
<-time.After(globalConfiguration.BackendsThrottleDuration)
|
||||
if time.Now().After(lastReceivedConfiguration.Add(time.Duration(globalConfiguration.BackendsThrottleDuration))) {
|
||||
log.Infof("Waited for %s config, OK", configMsg.providerName)
|
||||
configurationChanValidated <- *lastConfigs[configMsg.providerName]
|
||||
}
|
||||
}()
|
||||
}
|
||||
lastReceivedConfiguration = time.Now()
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
for {
|
||||
configMsg := <-configurationChanValidated
|
||||
log.Debugf("Configuration %s", spew.Sdump(configMsg.configuration))
|
||||
if configMsg.configuration == nil {
|
||||
log.Info("Skipping empty configuration")
|
||||
} else if reflect.DeepEqual(currentConfigurations[configMsg.providerName], configMsg.configuration) {
|
||||
|
@ -120,7 +145,7 @@ func main() {
|
|||
newsrv := prepareServer(configurationRouter, globalConfiguration, oldServer, loggerMiddleware, metrics)
|
||||
go startServer(newsrv, globalConfiguration)
|
||||
srv = newsrv
|
||||
time.Sleep(2 * time.Second)
|
||||
time.Sleep(1 * time.Second)
|
||||
if oldServer != nil {
|
||||
log.Info("Stopping old server")
|
||||
oldServer.Close()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue