minor cleanup
This commit is contained in:
parent
36b512d90b
commit
52d6c2d347
@ -17,6 +17,8 @@ import Database.Persist.Sql
|
||||
import Database.PostgreSQL.Simple (sqlErrorHint)
|
||||
import Control.Monad.Catch (handleIf)
|
||||
|
||||
import Data.Time.Clock
|
||||
|
||||
setSerializable :: (MonadLogger m, MonadCatch m, MonadBase IO m, MonadIO m) => ReaderT SqlBackend m a -> ReaderT SqlBackend m a
|
||||
setSerializable act = setSerializable' (0 :: Integer)
|
||||
where
|
||||
@ -24,7 +26,14 @@ setSerializable act = setSerializable' (0 :: Integer)
|
||||
|
||||
setSerializable' (min 10 -> logBackoff) =
|
||||
handleIf
|
||||
(\e -> sqlErrorHint e == "The transaction might succeed if retried.")
|
||||
(\e -> $logWarnS "Sql" (tshow e) *> threadDelay (1e3 * 2 ^ logBackoff) *> setSerializable' (succ logBackoff))
|
||||
(\e -> "The transaction might succeed if retried." `isInfixOf` sqlErrorHint e)
|
||||
(\e -> do
|
||||
let
|
||||
delay :: NominalDiffTime
|
||||
delay = 1e-3 * 2 ^ logBackoff
|
||||
$logWarnS "Sql" $ tshow (delay, e)
|
||||
threadDelay . round $ delay * 1e6
|
||||
setSerializable' (succ logBackoff)
|
||||
)
|
||||
act'
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user