summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarkfine <>2017-04-03 21:42:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2017-04-03 21:42:00 (GMT)
commitec8008e10c12aff7afc0d9ce1f4bb53df19f49da (patch)
treef279d1a83869cbfd99c3da923213eff7e645ff6d
parentc8aa6aedc2adcd2d38170e432a36451af2292e86 (diff)
version 0.3.90.3.9
-rw-r--r--src/Network/AWS/Wolf/Ctx.hs17
-rw-r--r--wolf.cabal2
2 files changed, 17 insertions, 2 deletions
diff --git a/src/Network/AWS/Wolf/Ctx.hs b/src/Network/AWS/Wolf/Ctx.hs
index a6d156f..0d7e4b3 100644
--- a/src/Network/AWS/Wolf/Ctx.hs
+++ b/src/Network/AWS/Wolf/Ctx.hs
@@ -17,11 +17,13 @@ module Network.AWS.Wolf.Ctx
, preAmazonDecisionCtx
) where
+import Control.Concurrent
import Control.Monad.Trans.AWS
import Data.Aeson
import Network.AWS.SWF
import Network.AWS.Wolf.Prelude
import Network.AWS.Wolf.Types
+import Network.HTTP.Types
-- | Handler for exceptions, traces and rethrows.
--
@@ -80,13 +82,26 @@ preAmazonStoreCtx preamble action = do
c <- view amazonStoreCtx <&> cPreamble <>~ preamble
runTransT c $ catch action catcher
+-- | Amazon throttle handler.
+--
+throttler :: MonadAmazon c m => m a -> Error -> m a
+throttler action e =
+ case e of
+ ServiceError se -> do
+ let delay = liftIO $ threadDelay $ 5 * 1000000
+ bool (throwIO e) (delay >> (catch action $ throttler action)) $
+ se ^. serviceStatus == badRequest400 &&
+ se ^. serviceCode == "Throttling"
+ _ ->
+ throwIO e
+
-- | Run amazon work context.
--
runAmazonWorkCtx :: MonadAmazon c m => Text -> TransT AmazonWorkCtx m a -> m a
runAmazonWorkCtx queue action = do
let preamble = [ "queue" .= queue ]
c <- view amazonCtx <&> cPreamble <>~ preamble
- runTransT (AmazonWorkCtx c queue) $ catch action catcher
+ runTransT (AmazonWorkCtx c queue) $ catch (catch action $ throttler action) catcher
-- | Update amazon context's preamble.
--
diff --git a/wolf.cabal b/wolf.cabal
index 520d8d2..b81dcc8 100644
--- a/wolf.cabal
+++ b/wolf.cabal
@@ -1,5 +1,5 @@
name: wolf
-version: 0.3.8
+version: 0.3.9
synopsis: Amazon Simple Workflow Service Wrapper.
description: Wolf is a wrapper around Amazon Simple Workflow Service.
homepage: https://github.com/swift-nav/wolf