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

Side by Side Diff: common/gcloud/pubsub/retry.go

Issue 1838303002: Use native Pub/Sub library primitives. (Closed) Base URL: https://github.com/luci/luci-go@logdog-go1.6
Patch Set: Use "Topic" instead of "NewTopic" ... don't want to create :) Created 4 years, 8 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 | « common/gcloud/pubsub/quota.go ('k') | common/gcloud/pubsub/scopes.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 2015 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 pubsub
6
7 import (
8 "github.com/luci/luci-go/common/retry"
9 "golang.org/x/net/context"
10 )
11
12 // Retry wraps a Connection and retries on transient errors.
13 type Retry struct {
14 // Connection is the base Connection to wrap and retry.
15 Connection
16
17 // Factory is the retry.Factory to use. If nil, retry.Default will be us ed.
18 Factory retry.Factory
19
20 // Callback, if not nil, will be called when an error is encountered.
21 Callback retry.Callback
22 }
23
24 // TopicExists implements the Connection interface.
25 func (r *Retry) TopicExists(c context.Context, t Topic) (exists bool, err error) {
26 err = retry.Retry(c, r.retryFactory(), func() (err error) {
27 exists, err = r.Connection.TopicExists(c, t)
28 return
29 }, r.Callback)
30 return
31 }
32
33 // SubExists implements the Connection interface.
34 func (r *Retry) SubExists(c context.Context, s Subscription) (exists bool, err e rror) {
35 err = retry.Retry(c, r.retryFactory(), func() (err error) {
36 exists, err = r.Connection.SubExists(c, s)
37 return
38 }, r.Callback)
39 return
40 }
41
42 // Publish implements the Connection interface.
43 func (r *Retry) Publish(c context.Context, t Topic, msgs ...*Message) (ids []str ing, err error) {
44 err = retry.Retry(c, r.retryFactory(), func() (err error) {
45 ids, err = r.Connection.Publish(c, t, msgs...)
46 return
47 }, r.Callback)
48 return
49 }
50
51 // Pull implements the Connection interface.
52 func (r *Retry) Pull(c context.Context, s Subscription, batch int) (msgs []*Mess age, err error) {
53 err = retry.Retry(c, r.retryFactory(), func() (err error) {
54 msgs, err = r.Connection.Pull(c, s, batch)
55 return
56 }, r.Callback)
57 return
58 }
59
60 // Ack implements the Connection interface.
61 func (r *Retry) Ack(c context.Context, s Subscription, ackIDs ...string) (err er ror) {
62 return retry.Retry(c, r.retryFactory(), func() error {
63 return r.Connection.Ack(c, s, ackIDs...)
64 }, r.Callback)
65 }
66
67 func (r *Retry) retryFactory() retry.Factory {
68 var f retry.Factory
69 if r.Factory != nil {
70 f = r.Factory
71 } else {
72 f = retry.Default
73 }
74 return retry.TransientOnly(f)
75 }
OLDNEW
« no previous file with comments | « common/gcloud/pubsub/quota.go ('k') | common/gcloud/pubsub/scopes.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698