Skip to content

Commit

Permalink
Add retry for service watch (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
jojimt authored and shaleman committed Sep 14, 2016
1 parent 769c7ec commit 75ae6c7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions etcdService.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,22 @@ func (ep *EtcdClient) GetService(name string) ([]ServiceInfo, error) {

func (ep *EtcdClient) getServiceState(key string) (uint64, []ServiceInfo, error) {
var srvcList []ServiceInfo
retryCount := 0

// Get the object from etcd client
resp, err := ep.kapi.Get(context.Background(), key, &client.GetOptions{Recursive: true, Sort: true})
for err != nil && err.Error() == client.ErrClusterUnavailable.Error() {
// Retry after a delay
retryCount++
if retryCount%16 == 0 {
log.Warnf("%v -- Retrying...", err)
}

time.Sleep(time.Second)
resp, err = ep.kapi.Get(context.Background(), key,
&client.GetOptions{Recursive: true, Sort: true})
}

if err != nil {
if strings.Contains(err.Error(), "Key not found") {
return 0, nil, nil
Expand Down

0 comments on commit 75ae6c7

Please sign in to comment.