fix registry TTL. (#1537)

* fix registry.
1. When etcd stops, the application cannot stop.
2. Stop consul first, then stop app. Then start consul, the registered service remains in consul registry as an unhealthy status.

Co-authored-by: corel <corelchen@qq.com>
pull/1541/head
aiscrm 3 years ago committed by GitHub
parent 69fc5cca87
commit 9743ad8d32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app.go
  2. 14
      contrib/registry/consul/client.go

@ -117,6 +117,7 @@ func (a *App) Run() error {
err := a.Stop() err := a.Stop()
if err != nil { if err != nil {
a.opts.logger.Errorf("failed to stop app: %v", err) a.opts.logger.Errorf("failed to stop app: %v", err)
return err
} }
} }
} }

@ -90,17 +90,19 @@ func (d *Client) Register(ctx context.Context, svc *registry.ServiceInstance, en
Port: int(port), Port: int(port),
Checks: []*api.AgentServiceCheck{ Checks: []*api.AgentServiceCheck{
{ {
CheckID: "service:" + svc.ID, CheckID: "service:" + svc.ID,
TTL: "50s", TTL: "30s",
Status: "passing", Status: "passing",
DeregisterCriticalServiceAfter: "90s",
}, },
}, },
} }
if enableHealthCheck { if enableHealthCheck {
asr.Checks = append(asr.Checks, &api.AgentServiceCheck{ asr.Checks = append(asr.Checks, &api.AgentServiceCheck{
TCP: fmt.Sprintf("%s:%d", addr, port), TCP: fmt.Sprintf("%s:%d", addr, port),
Interval: "20s", Interval: "20s",
Status: "passing", Status: "passing",
DeregisterCriticalServiceAfter: "90s",
}) })
} }
err := d.cli.Agent().ServiceRegister(asr) err := d.cli.Agent().ServiceRegister(asr)

Loading…
Cancel
Save