add comment to broker
This commit is contained in:
parent
27b6049460
commit
2c5b50ddf8
1 changed files with 6 additions and 8 deletions
14
broker.go
14
broker.go
|
|
@ -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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue