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:
parent
97ffabeaa5
commit
3f2519e51c
1 changed files with 23 additions and 22 deletions
17
consumer.go
17
consumer.go
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue