Run initial scan immediately (#123)

Rather than starting the shard scan loop and waiting for next scan tick before
fetching any data, do the first poll immediately, and then wait.
This commit is contained in:
Jason Tackaberry 2020-08-01 18:45:37 -04:00 committed by GitHub
parent 97ffabeaa5
commit 3f2519e51c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -158,10 +158,6 @@ func (c *Consumer) ScanShard(ctx context.Context, shardID string, fn ScanFunc) e
defer scanTicker.Stop()
for {
select {
case <-ctx.Done():
return nil
case <-scanTicker.C:
resp, err := c.client.GetRecords(&kinesis.GetRecordsInput{
Limit: aws.Int64(c.maxRecords),
ShardIterator: shardIterator,
@ -181,10 +177,7 @@ func (c *Consumer) ScanShard(ctx context.Context, shardID string, fn ScanFunc) e
if err != nil {
return fmt.Errorf("get shard iterator error: %v", err)
}
continue
}
} else {
// loop over records, call callback func
for _, r := range resp.Records {
select {
@ -214,6 +207,14 @@ func (c *Consumer) ScanShard(ctx context.Context, shardID string, fn ScanFunc) e
shardIterator = resp.NextShardIterator
}
// Wait for next scan
select {
case <-ctx.Done():
return nil
case <-scanTicker.C:
continue
}
}
}