Skip to content

Commit

Permalink
fix ThrottlingException handling, return the current token and start …
Browse files Browse the repository at this point in the history
…position
  • Loading branch information
tj committed Mar 25, 2019
1 parent 09a6af3 commit 985a824
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
module github.com/tj/aws

go 1.12

require (
github.com/apex/log v1.1.0
github.com/aws/aws-sdk-go v1.19.1
github.com/pkg/errors v0.8.1 // indirect
)
15 changes: 6 additions & 9 deletions logs/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ func (g *group) start(ch chan<- *Event) {
g.log.WithField("start", start).Debug("request")
nextToken, start, err = g.fetch(nextToken, start, ch)

if e, ok := err.(awserr.Error); ok {
if e.Code() == "ThrottlingException" {
g.log.Debug("throttled")
time.Sleep(time.Second * 2)
continue
}
}

if err != nil {
g.err = fmt.Errorf("log %q: %s", g.name, err)
break
Expand Down Expand Up @@ -77,7 +69,12 @@ func (g *group) fetch(nextToken *string, start int64, ch chan<- *Event) (*string
})

if e, ok := err.(awserr.Error); ok {
if e.Code() == "ResourceNotFoundException" {
switch e.Code() {
case "ThrottlingException":
g.log.Debug("throttled")
time.Sleep(time.Second * 2)
return nextToken, start, nil
case "ResourceNotFoundException":
g.log.Debug("not found")
return nil, 0, nil
}
Expand Down

0 comments on commit 985a824

Please sign in to comment.