@@ -71,7 +71,7 @@ import qualified Database.PostgreSQL.Simple.Transaction as PG
71
71
import qualified Database.PostgreSQL.Simple.Types as PG
72
72
73
73
import Control.Arrow
74
- import Control.Exception (Exception , throw , throwIO )
74
+ import Control.Exception (Exception , throw , throwIO , catches , Handler ( Handler ) )
75
75
import Control.Monad
76
76
import Control.Monad.Except
77
77
import Control.Monad.IO.Unlift (MonadIO (.. ), MonadUnliftIO )
@@ -119,6 +119,9 @@ import Database.Persist.Postgresql.Internal
119
119
import Database.Persist.Sql
120
120
import qualified Database.Persist.Sql.Util as Util
121
121
import Database.Persist.SqlBackend
122
+ import Database.PostgreSQL.Simple (SqlError )
123
+ import System.IO (hPutStr , stderr )
124
+ import Control.Concurrent (threadDelay )
122
125
123
126
-- | A @libpq@ connection string. A simple example of connection
124
127
-- string would be @\"host=localhost port=5432 user=test
@@ -288,7 +291,12 @@ open'
288
291
-- pass in 'withRawConnection'.
289
292
-> ConnectionString -> LogFunc -> IO backend
290
293
open' modConn getVer constructor cstr logFunc = do
291
- conn <- PG. connectPostgreSQL cstr
294
+ conn <- fix $ \ loop' ->
295
+ PG. connectPostgreSQL cstr `catches` [
296
+ Handler (\ (ex :: IOError ) -> hPutStr stderr (" Warning: DB not ready (PQ.PollingFailed)" ++ " : " ++ show ex)
297
+ >> threadDelay 3000000 >> loop'),
298
+ Handler (\ (ex :: SqlError ) -> hPutStr stderr (" Warning: DB not ready (fatalError)" ++ " : " ++ show ex)
299
+ >> threadDelay 3000000 >> loop')]
292
300
modConn conn
293
301
ver <- getVer conn
294
302
smap <- newIORef $ Map. empty
0 commit comments