mirror of https://github.com/docker/docs.git
Merge pull request #841 from abronan/consul_ttl_check
Additional check for ttl < 10s and Consul
This commit is contained in:
commit
fa2809d431
|
@ -62,6 +62,7 @@ func (s *Discovery) Initialize(uris string, heartbeat time.Duration, ttl time.Du
|
|||
EphemeralTTL: s.ttl,
|
||||
},
|
||||
)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,10 @@ const (
|
|||
// watched key has changed. This affects the minimum time it takes to
|
||||
// cancel a watch.
|
||||
DefaultWatchWaitTime = 15 * time.Second
|
||||
|
||||
// MinimumTimeToLive is the minimum TTL value allowed by Consul for
|
||||
// Ephemeral entries
|
||||
MinimumTimeToLive = 10 * time.Second
|
||||
)
|
||||
|
||||
// Consul embeds the client and watches
|
||||
|
@ -52,7 +56,9 @@ func InitializeConsul(endpoints []string, options *Config) (Store, error) {
|
|||
s.setTimeout(options.ConnectionTimeout)
|
||||
}
|
||||
if options.EphemeralTTL != 0 {
|
||||
s.setEphemeralTTL(options.EphemeralTTL)
|
||||
if err := s.setEphemeralTTL(options.EphemeralTTL); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,8 +87,12 @@ func (s *Consul) setTimeout(time time.Duration) {
|
|||
}
|
||||
|
||||
// SetEphemeralTTL sets the ttl for ephemeral nodes
|
||||
func (s *Consul) setEphemeralTTL(time time.Duration) {
|
||||
s.ephemeralTTL = time
|
||||
func (s *Consul) setEphemeralTTL(ttl time.Duration) error {
|
||||
if ttl < MinimumTimeToLive {
|
||||
return ErrInvalidTTL
|
||||
}
|
||||
s.ephemeralTTL = ttl
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateEphemeralSession creates the a global session
|
||||
|
|
|
@ -23,6 +23,8 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
// ErrInvalidTTL is a specific error to consul
|
||||
ErrInvalidTTL = errors.New("Invalid TTL, please change the value to the miminum allowed ttl for the chosen store")
|
||||
// ErrNotSupported is exported
|
||||
ErrNotSupported = errors.New("Backend storage not supported yet, please choose another one")
|
||||
// ErrNotImplemented is exported
|
||||
|
|
Loading…
Reference in New Issue