postgresql-resilient-0.1.0.0: Automatic re-connection support for PostgreSQL
LicenseApache-2.0
Maintainervolpegabriel@gmail.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

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

Documentation

data ResilientConnection m Source #

Single connection pool with built-in reconnection

Constructors

ResilientConnection 

Fields

data ResilientSettings Source #

The resilient settings

Constructors

ResilientSettings 

Fields

data Seconds Source #

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