add comment to broker

This commit is contained in:
Harlow Ward 2019-04-08 20:33:39 -07:00
parent 27b6049460
commit 2c5b50ddf8

View file

@ -11,11 +11,9 @@ import (
"github.com/aws/aws-sdk-go/service/kinesis/kinesisiface" "github.com/aws/aws-sdk-go/service/kinesis/kinesisiface"
) )
func newBroker( const pollFreq = 30 * time.Second
client kinesisiface.KinesisAPI,
streamName string, func newBroker(client kinesisiface.KinesisAPI, streamName string, shardc chan *kinesis.Shard) *broker {
shardc chan *kinesis.Shard,
) *broker {
return &broker{ return &broker{
client: client, client: client,
shards: make(map[string]*kinesis.Shard), shards: make(map[string]*kinesis.Shard),
@ -24,6 +22,8 @@ func newBroker(
} }
} }
// broker keeps local cache list of the shard we are already processing
// and routinely polls the stream looking for new shards to process
type broker struct { type broker struct {
client kinesisiface.KinesisAPI client kinesisiface.KinesisAPI
streamName string streamName string
@ -36,14 +36,12 @@ type broker struct {
func (b *broker) pollShards(ctx context.Context) { func (b *broker) pollShards(ctx context.Context) {
b.fetchShards() b.fetchShards()
// TODO: also add signal to re-poll
go func() { go func() {
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
return return
case <-time.After(30 * time.Second): case <-time.After(pollFreq):
b.fetchShards() b.fetchShards()
} }
} }