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

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: Comments, rebase. 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
« no previous file with comments | « server/internal/logdog/config/flag_test.go ('k') | server/internal/logdog/service/service.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/proto/google"
13 "github.com/luci/luci-go/common/retry"
14 "golang.org/x/net/context"
15 "google.golang.org/grpc"
16 )
17
18 // client wraps a services.ServicesClient, retrying transient errors.
19 type client struct {
20 // Client is the CoordinatorClient that is being wrapped.
21 c s.ServicesClient
22
23 // f is the retry.Generator to use to generate retry.Iterator instances. If
24 // nil, retry.Default will be used.
25 f retry.Factory
26 }
27
28 // New wraps a supplied services.ServicesClient instance, automatically retrying
29 // transient errors.
30 //
31 // If the supplied retry factory is nil, retry.Default will be used.
32 func New(c s.ServicesClient, f retry.Factory) s.ServicesClient {
33 if f == nil {
34 f = retry.Default
35 }
36 return &client{c, retry.TransientOnly(f)}
37 }
38
39 func (c *client) GetConfig(ctx context.Context, in *google.Empty, opts ...grpc.C allOption) (r *s.GetConfigResponse, err error) {
40 err = retry.Retry(ctx, c.f, func() (err error) {
41 r, err = c.c.GetConfig(ctx, in, opts...)
42 return
43 }, callback(ctx, "registering stream"))
44 return
45 }
46
47 func (c *client) RegisterStream(ctx context.Context, in *s.RegisterStreamRequest , opts ...grpc.CallOption) (
48 r *s.LogStreamState, err error) {
49 err = retry.Retry(ctx, c.f, func() (err error) {
50 r, err = c.c.RegisterStream(ctx, in, opts...)
51 return
52 }, callback(ctx, "registering stream"))
53 return
54 }
55
56 func (c *client) TerminateStream(ctx context.Context, in *s.TerminateStreamReque st, opts ...grpc.CallOption) (
57 r *google.Empty, err error) {
58 err = retry.Retry(ctx, c.f, func() (err error) {
59 r, err = c.c.TerminateStream(ctx, in, opts...)
60 return
61 }, callback(ctx, "terminating stream"))
62 return
63 }
64
65 func callback(ctx context.Context, op string) retry.Callback {
66 return func(err error, d time.Duration) {
67 log.Fields{
68 log.ErrorKey: err,
69 "delay": d,
70 }.Errorf(ctx, "Transient error %s. Retrying...", op)
71 }
72 }
OLDNEW
« no previous file with comments | « server/internal/logdog/config/flag_test.go ('k') | server/internal/logdog/service/service.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698