pull out the log.Fatal from pkg/store to the discovery level

Signed-off-by: Alexandre Beslic <abronan@docker.com>
This commit is contained in:
Alexandre Beslic 2015-05-26 11:01:17 -07:00
parent bf6427ad23
commit 96241c6b79
3 changed files with 18 additions and 4 deletions

View File

@ -61,9 +61,17 @@ func (s *Discovery) Initialize(uris string, heartbeat time.Duration, ttl time.Du
EphemeralTTL: s.ttl,
},
)
if err != nil {
if err == store.ErrInvalidTTL {
log.Fatal(err)
}
return err
}
return nil
}
// Watch the store until either there's a store error or we receive a stop request.
// Returns false if we shouldn't attempt watching the store anymore (stop request received).
func (s *Discovery) watchOnce(stopCh <-chan struct{}, watchCh <-chan []*store.KVPair, discoveryCh chan discovery.Entries, errCh chan error) bool {

View File

@ -56,7 +56,10 @@ func InitializeConsul(endpoints []string, options *Config) (Store, error) {
s.setTimeout(options.ConnectionTimeout)
}
if options.EphemeralTTL != 0 {
s.setEphemeralTTL(options.EphemeralTTL)
err := s.setEphemeralTTL(options.EphemeralTTL)
if err != nil {
return nil, err
}
}
}
@ -85,11 +88,12 @@ func (s *Consul) setTimeout(time time.Duration) {
}
// SetEphemeralTTL sets the ttl for ephemeral nodes
func (s *Consul) setEphemeralTTL(ttl time.Duration) {
func (s *Consul) setEphemeralTTL(ttl time.Duration) error {
if ttl < MinimumTimeToLive {
log.Fatal("Consul does not allow a ttl < 10s, please specify a ttl >= 10s")
return ErrInvalidTTL
}
s.ephemeralTTL = ttl
return nil
}
// CreateEphemeralSession creates the a global session

View File

@ -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