2018-06-05 03:07:58 +00:00
|
|
|
package ddb
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
|
|
|
"github.com/aws/aws-sdk-go/service/dynamodb"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Retryer interface contains one method that decides whether to retry based on error
|
|
|
|
|
type Retryer interface {
|
|
|
|
|
ShouldRetry(error) bool
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-01 01:43:26 +00:00
|
|
|
// DefaultRetryer .
|
2018-06-05 03:07:58 +00:00
|
|
|
type DefaultRetryer struct {
|
|
|
|
|
Retryer
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-01 01:43:26 +00:00
|
|
|
// ShouldRetry when error occured
|
2018-06-05 03:07:58 +00:00
|
|
|
func (r *DefaultRetryer) ShouldRetry(err error) bool {
|
|
|
|
|
if awsErr, ok := err.(awserr.Error); ok {
|
|
|
|
|
if awsErr.Code() == dynamodb.ErrCodeProvisionedThroughputExceededException {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|