Comments (1)
Since the ticket is still open, I'll mention here:
Our retry package helps with this quite trivially: http://hackage.haskell.org/package/retry
Here's an example from how we handle retries in application logic:
-------------------------------------------------------------------------------
runAws
:: (Transaction r b, MonadIO n,
MonadReader AppEnv n, MonadCatch n)
=> ServiceConfiguration r NormalQuery
-> Int
-- ^ Number of retries
-> r
-- ^ Request
-> ResourceT n b
runAws servConf n r = do
mgr <- view appManager
conf <- view appAwsConfig
recovering (awsPolicy n) [kinesisH echo, httpRetryH, networkRetryH] $
hoist liftIO $
pureAws conf servConf mgr r
with
-------------------------------------------------------------------------------
kinesisH
:: MonadIO m
=> (String -> m ())
-- ^ How to (and whether to) report errors
-> Int
-- ^ Retry number
-> Handler m Bool
kinesisH report n = handleLog chk report n
where
chk e = return $ case e of
KinesisErrorResponse cd _msg -> case cd of
"ProvisionedThroughputExceededException" -> True
_ -> False
KinesisOtherError stat _ -> case stat of
Status _ "Internal Server Error" -> True
Status _ "Service Unavailable" -> True
_ -> False
_ -> False
-------------------------------------------------------------------------------
awsPolicy :: Int -> RetryPolicy
awsPolicy n = capDelay 60000000 $
mempty <> limitRetries n <> exponentialBackoff 25000
-------------------------------------------------------------------------------
-- | Which exceptions should we retry?
httpRetryH :: MonadIO m => Int -> Handler m Bool
httpRetryH n = handleLog (return . httpRetry) echo n
-------------------------------------------------------------------------------
-- | Should given exception be retried?
httpRetry :: HttpException -> Bool
httpRetry e =
case e of
TooManyRetries{} -> True
ResponseTimeout{} -> True
FailedConnectionException{} -> True
FailedConnectionException2{} -> True
InternalIOException{} -> True
ProxyConnectException{} -> True
StatusCodeException{} -> True
NoResponseDataReceived{} -> True
ResponseBodyTooShort{} -> True
InvalidChunkHeaders{} -> True
IncompleteHeaders{} -> True
TlsException{} -> True
_ -> False
-------------------------------------------------------------------------------
-- | 'IOException's should be retried
networkRetryH :: MonadIO m => Int -> Handler m Bool
networkRetryH n = handleLog chk echo n
where
chk (_ :: IOException) = return True
-------------------------------------------------------------------------------
-- | Handle exception while logging it.
handleLog
:: (Monad m, Show e, Exception e)
=> (e -> m Bool)
-- ^ Test for whether action is to be retried
-> (String -> m ())
-- ^ How ot report the generated warning message.
-> Int
-- ^ Retry number
-> Handler m Bool
handleLog f report n = Handler $ \ e -> do
res <- f e
let msg = "[retry:" <> show n <> "] Encountered " <> show e <> ". " <>
if res then "Retrying." else "Crashing."
report msg
return res
from aws.
Related Issues (20)
- PutBucket versioning HOT 2
- add etag to PutObjectResponse
- add etag to GetBucketResponse HOT 1
- S3 Buckets with "." in the name cause TLS issues when running PutObject HOT 1
- v4 GetObject Signing HOT 5
- Support for network 3.x?
- DynamoDB conditions: Missing `attribute_not_exists`? HOT 2
- Json support for basic types
- `credentialsDefaultFile` references non-standard location
- Support HTTP and custom port in SES HOT 1
- SES no longer works HOT 2
- Build errors with aeson-2 HOT 3
- New maintainer or at least contributor HOT 8
- support unauthenticated S3 requests HOT 4
- Kinesis support
- HTTP2 support
- unable to specify a region for S3 servers not in AWS HOT 2
- unable to specify User-Agent
- software design HOT 1
- Build error with aeson 2.2 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws.