From c289f6acaa54cc07079762681ead39bc23a91dc4 Mon Sep 17 00:00:00 2001 From: Asim Date: Fri, 25 Nov 2016 11:23:37 +0100 Subject: [PATCH] Make use of consul 0.7 deregister field. Now auto reaps dead services --- registry/consul_registry.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/registry/consul_registry.go b/registry/consul_registry.go index ec906450..448616a1 100644 --- a/registry/consul_registry.go +++ b/registry/consul_registry.go @@ -153,8 +153,17 @@ func (c *consulRegistry) Register(s *Service, opts ...RegisterOption) error { // if the TTL is greater than 0 create an associated check if options.TTL > time.Duration(0) { + // splay slightly for the watcher? + splay := time.Second * 5 + deregTTL := options.TTL + splay + // consul has a minimum timeout on deregistration of 1 minute. + if options.TTL < time.Minute { + deregTTL = time.Minute + splay + } + check = &consul.AgentServiceCheck{ TTL: fmt.Sprintf("%v", options.TTL), + DeregisterCriticalServiceAfter: fmt.Sprintf("%v", deregTTL), } }