Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/gcps" | |
| 9 "golang.org/x/net/context" | |
| 10 ) | |
| 11 | |
| 12 // Acknowledger sends ACKs to a Pub/Sub interface. | |
| 13 // | |
| 14 // gcps.PubSub naturally implements this interface. | |
| 15 type Acknowledger interface { | |
|
dnj (Google)
2016/01/21 04:36:24
These changes allow better interoperability betwee
| |
| 16 // Ack acknowledges one or more Pub/Sub message ACK IDs. | |
| 17 Ack(ctx context.Context, ackIDs ...string) error | |
| 18 | |
| 19 // AckBatchSize returns the maximum number of ACKs that can be sent at a time. | |
| 20 AckBatchSize() int | |
| 21 } | |
| 22 | |
| 23 type gcpsACK struct { | |
| 24 ps gcps.PubSub | |
| 25 sub gcps.Subscription | |
| 26 batch int | |
| 27 } | |
| 28 | |
| 29 // NewACK creates a Acknowledger instance from a gcps.PubSub implementation. | |
| 30 // | |
| 31 // If batch is <= 0, the maximum ACK batch size will be used. | |
| 32 func NewACK(ps gcps.PubSub, s gcps.Subscription, batch int) Acknowledger { | |
| 33 if batch <= 0 { | |
| 34 batch = gcps.MaxMessageAckPerRequest | |
| 35 } | |
| 36 | |
| 37 return &gcpsACK{ | |
| 38 ps: ps, | |
| 39 sub: s, | |
| 40 batch: batch, | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 func (a *gcpsACK) Ack(c context.Context, ackIDs ...string) error { | |
| 45 return a.ps.Ack(c, a.sub, ackIDs...) | |
| 46 } | |
| 47 | |
| 48 func (a *gcpsACK) AckBatchSize() int { | |
| 49 return a.batch | |
| 50 } | |
| OLD | NEW |