| 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/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 } | |
| OLD | NEW |