Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(446)

Side by Side Diff: logdog/server/retryServicesClient/client.go

Issue 2951393002: [errors] de-specialize Transient in favor of Tags. (Closed)
Patch Set: more refactor Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package retryServicesClient 5 package retryServicesClient
6 6
7 import ( 7 import (
8 "time" 8 "time"
9 9
10 "github.com/golang/protobuf/ptypes/empty" 10 "github.com/golang/protobuf/ptypes/empty"
11 log "github.com/luci/luci-go/common/logging" 11 log "github.com/luci/luci-go/common/logging"
12 "github.com/luci/luci-go/common/retry" 12 "github.com/luci/luci-go/common/retry"
13 "github.com/luci/luci-go/common/retry/transient"
13 "github.com/luci/luci-go/grpc/grpcutil" 14 "github.com/luci/luci-go/grpc/grpcutil"
14 s "github.com/luci/luci-go/logdog/api/endpoints/coordinator/services/v1" 15 s "github.com/luci/luci-go/logdog/api/endpoints/coordinator/services/v1"
15 "golang.org/x/net/context" 16 "golang.org/x/net/context"
16 "google.golang.org/grpc" 17 "google.golang.org/grpc"
17 ) 18 )
18 19
19 // client wraps a services.ServicesClient, retrying transient errors. 20 // client wraps a services.ServicesClient, retrying transient errors.
20 type client struct { 21 type client struct {
21 // Client is the CoordinatorClient that is being wrapped. 22 // Client is the CoordinatorClient that is being wrapped.
22 c s.ServicesClient 23 c s.ServicesClient
23 24
24 // f is the retry.Generator to use to generate retry.Iterator instances. If 25 // f is the retry.Generator to use to generate retry.Iterator instances. If
25 // nil, retry.Default will be used. 26 // nil, retry.Default will be used.
26 f retry.Factory 27 f retry.Factory
27 } 28 }
28 29
29 // New wraps a supplied services.ServicesClient instance, automatically retrying 30 // New wraps a supplied services.ServicesClient instance, automatically retrying
30 // transient errors. 31 // transient errors.
31 // 32 //
32 // If the supplied retry factory is nil, retry.Default will be used. 33 // If the supplied retry factory is nil, retry.Default will be used.
33 func New(c s.ServicesClient, f retry.Factory) s.ServicesClient { 34 func New(c s.ServicesClient, f retry.Factory) s.ServicesClient {
34 if f == nil { 35 if f == nil {
35 f = retry.Default 36 f = retry.Default
36 } 37 }
37 » return &client{c, retry.TransientOnly(f)} 38 » return &client{c, transient.Only(f)}
38 } 39 }
39 40
40 func (c *client) GetConfig(ctx context.Context, in *empty.Empty, opts ...grpc.Ca llOption) (r *s.GetConfigResponse, err error) { 41 func (c *client) GetConfig(ctx context.Context, in *empty.Empty, opts ...grpc.Ca llOption) (r *s.GetConfigResponse, err error) {
41 err = retry.Retry(ctx, c.f, func() (err error) { 42 err = retry.Retry(ctx, c.f, func() (err error) {
42 r, err = c.c.GetConfig(ctx, in, opts...) 43 r, err = c.c.GetConfig(ctx, in, opts...)
43 err = grpcutil.WrapIfTransient(err) 44 err = grpcutil.WrapIfTransient(err)
44 return 45 return
45 }, callback(ctx, "registering stream")) 46 }, callback(ctx, "registering stream"))
46 return 47 return
47 } 48 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 88 }
88 89
89 func callback(ctx context.Context, op string) retry.Callback { 90 func callback(ctx context.Context, op string) retry.Callback {
90 return func(err error, d time.Duration) { 91 return func(err error, d time.Duration) {
91 log.Fields{ 92 log.Fields{
92 log.ErrorKey: err, 93 log.ErrorKey: err,
93 "delay": d, 94 "delay": d,
94 }.Errorf(ctx, "Transient error %s. Retrying...", op) 95 }.Errorf(ctx, "Transient error %s. Retrying...", op)
95 } 96 }
96 } 97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698