| License | Apache-2.0 |
|---|---|
| Maintainer | volpegabriel@gmail.com |
| Stability | experimental |
| Safe Haskell | None |
| Language | Haskell2010 |
Database.PostgreSQL.Resilient
Description
The withResilientConnection function gives us a ResilientConnection from which we can always get a health connection, while automatic reconnection with retries and exponential back-offs are being handled in the background.
import Database.PostgreSQL.Resilient
import qualified Database.PostgreSQL.Simple as P
withResilientConnection defaultResilientSettings logHandler connectInfo $ pool ->
(conn :: P.Connection) <- getConnection pool
res <- P.query_ conn "SELECT * FROM foo"
putStrLn $ show res
logHandler :: String -> IO ()
logHandler = putStrLn
connectInfo :: P.ConnectInfo
connectInfo = P.ConnectInfo
{ P.connectHost = "localhost"
, P.connectPort = 5432
, P.connectUser = "postgres"
, P.connectPassword = ""
, P.connectDatabase = "store"
}
defaultResilientSettings :: ResilientSettings
defaultResilientSettings = ResilientSettings
{ healthCheckEvery = 3
, exponentialBackoffThreshold = 10
}
Synopsis
- data ResilientConnection m = ResilientConnection {
- getConnection :: m Connection
- data ResilientSettings = ResilientSettings {}
- data Seconds
- withResilientConnection :: forall a. ResilientSettings -> LogHandler -> ConnectInfo -> (ResilientConnection IO -> IO a) -> IO a
- defaultResilientSettings :: ResilientSettings
Documentation
data ResilientConnection m Source #
Single connection pool with built-in reconnection
Constructors
| ResilientConnection | |
Fields
| |
data ResilientSettings Source #
The resilient settings
Constructors
| ResilientSettings | |
Fields
| |
Instances
| Show ResilientSettings Source # | |
Defined in Database.PostgreSQL.Resilient Methods showsPrec :: Int -> ResilientSettings -> ShowS # show :: ResilientSettings -> String # showList :: [ResilientSettings] -> ShowS # | |
Represents amount of seconds
withResilientConnection :: forall a. ResilientSettings -> LogHandler -> ConnectInfo -> (ResilientConnection IO -> IO a) -> IO a Source #
Returns a ResilientConnection from which you can always acquire the latest connection available.
-
- Reconnections with configurable retries and exponential back-offs as well as closing the connection once done using it (guaranteed by bracket) are too handled by this function.
-
defaultResilientSettings :: ResilientSettings Source #
Default resilient settings