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

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

Issue 1610993002: LogDog: Add collector service implementation. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Reorganized, cleaned up, comments, and updated for pRPC. Created 4 years, 10 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package retryServicesClient
6
7 import (
8 "time"
9
10 s "github.com/luci/luci-go/common/api/logdog_coordinator/services/v1"
11 log "github.com/luci/luci-go/common/logging"
12 "github.com/luci/luci-go/common/retry"
13 "golang.org/x/net/context"
14 "google.golang.org/grpc"
15 )
16
17 // client wraps a services.ServicesClient, retrying transient errors.
18 type client struct {
19 // Client is the CoordinatorClient that is being wrapped.
20 c s.ServicesClient
21
22 // f is the retry.Generator to use to generate retry.Iterator instances. If
23 // nil, retry.Default will be used.
24 f retry.Factory
25 }
26
27 // New wraps a supplied services.ServicesClient instance, automatically retrying
28 // transient errors.
29 //
30 // If the supplied retry factory is nil, retry.Default will be used.
31 func New(c s.ServicesClient, f retry.Factory) s.ServicesClient {
32 if f == nil {
33 f = retry.Default
34 }
35 return &client{c, retry.TransientOnly(f)}
36 }
37
38 func (c *client) GetConfig(ctx context.Context, in *s.Void, opts ...grpc.CallOpt ion) (r *s.GetConfigResponse, err error) {
39 err = retry.Retry(ctx, c.f, func() (err error) {
40 r, err = c.c.GetConfig(ctx, in, opts...)
41 return
42 }, callback(ctx, "registering stream"))
43 return
44 }
45
46 func (c *client) RegisterStream(ctx context.Context, in *s.RegisterStreamRequest , opts ...grpc.CallOption) (
47 r *s.LogStreamState, err error) {
48 err = retry.Retry(ctx, c.f, func() (err error) {
49 r, err = c.c.RegisterStream(ctx, in, opts...)
50 return
51 }, callback(ctx, "registering stream"))
52 return
53 }
54
55 func (c *client) TerminateStream(ctx context.Context, in *s.TerminateStreamReque st, opts ...grpc.CallOption) (
56 r *s.Void, err error) {
57 err = retry.Retry(ctx, c.f, func() (err error) {
58 r, err = c.c.TerminateStream(ctx, in, opts...)
59 return
60 }, callback(ctx, "terminating stream"))
61 return
62 }
63
64 func callback(ctx context.Context, op string) retry.Callback {
65 return func(err error, d time.Duration) {
66 log.Fields{
67 log.ErrorKey: err,
68 "delay": d,
69 }.Errorf(ctx, "Transient error %s. Retrying...", op)
70 }
71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698