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

Side by Side Diff: common/gcloud/pubsub/ackbuffer/ack.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
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 ackbuffer
6
7 import (
8 "github.com/luci/luci-go/common/gcloud/pubsub"
9 "golang.org/x/net/context"
10 )
11
12 // Acknowledger sends ACKs to a Pub/Sub interface.
13 type Acknowledger interface {
14 // Ack acknowledges one or more Pub/Sub message ACK IDs.
15 Ack(ctx context.Context, ackIDs ...string) error
16
17 // AckBatchSize returns the maximum number of ACKs that can be sent at a time.
18 AckBatchSize() int
19 }
20
21 type pubsubACK struct {
22 ps pubsub.Connection
23 sub pubsub.Subscription
24 batch int
25 }
26
27 // NewACK creates a Acknowledger instance from a pubsub.Connection
28 // implementation.
29 //
30 // If batch is <= 0, the maximum ACK batch size will be used.
31 func NewACK(ps pubsub.Connection, s pubsub.Subscription, batch int) Acknowledger {
32 if batch <= 0 {
33 batch = pubsub.MaxMessageAckPerRequest
34 }
35
36 return &pubsubACK{
37 ps: ps,
38 sub: s,
39 batch: batch,
40 }
41 }
42
43 func (a *pubsubACK) Ack(c context.Context, ackIDs ...string) error {
44 return a.ps.Ack(c, a.sub, ackIDs...)
45 }
46
47 func (a *pubsubACK) AckBatchSize() int {
48 return a.batch
49 }
OLDNEW
« no previous file with comments | « client/internal/logdog/butler/output/pubsub/pubsubOutput_test.go ('k') | common/gcloud/pubsub/ackbuffer/ackbuffer.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698