refactor: more accurate naming and documentation for connectionStatus

This commit is contained in:
Robert Vollmert
2022-08-29 14:55:09 +02:00
committed by Robert
parent 79b865ba79
commit cdce929159
+8 -7
View File
@@ -68,13 +68,13 @@ connectionWorker appState = do
work = do work = do
AppConfig{..} <- AppState.getConfig appState AppConfig{..} <- AppState.getConfig appState
AppState.logWithZTime appState "Attempting to connect to the database..." AppState.logWithZTime appState "Attempting to connect to the database..."
connected <- connectionStatus appState connected <- establishConnection appState
case connected of case connected of
FatalConnectionError reason -> FatalConnectionError reason ->
-- Fatal error when connecting -- Fatal error when connecting
AppState.logWithZTime appState reason >> killThread (AppState.getMainThreadId appState) AppState.logWithZTime appState reason >> killThread (AppState.getMainThreadId appState)
NotConnected -> NotConnected ->
-- Unreachable because connectionStatus will keep trying to connect -- Unreachable because establishConnection will keep trying to connect
return () return ()
Connected actualPgVersion -> do Connected actualPgVersion -> do
-- Procede with initialization -- Procede with initialization
@@ -97,17 +97,18 @@ connectionWorker appState = do
-- die if our schema cache query has an error -- die if our schema cache query has an error
killThread $ AppState.getMainThreadId appState killThread $ AppState.getMainThreadId appState
-- | Check if a connection from the pool allows access to the PostgreSQL -- | Repeatedly flush the pool, and check if a connection from the
-- database. If not, the pool connections are released and a new connection is -- pool allows access to the PostgreSQL database.
-- tried. Releasing the pool is key for rapid recovery. Otherwise, the pool --
-- Releasing the pool is key for rapid recovery. Otherwise, the pool
-- timeout would have to be reached for new healthy connections to be acquired. -- timeout would have to be reached for new healthy connections to be acquired.
-- Which might not happen if the server is busy with requests. No idle -- Which might not happen if the server is busy with requests. No idle
-- connection, no pool timeout. -- connection, no pool timeout.
-- --
-- The connection tries are capped, but if the connection times out no error is -- The connection tries are capped, but if the connection times out no error is
-- thrown, just 'False' is returned. -- thrown, just 'False' is returned.
connectionStatus :: AppState -> IO ConnectionStatus establishConnection :: AppState -> IO ConnectionStatus
connectionStatus appState = establishConnection appState =
retrying retrySettings shouldRetry $ retrying retrySettings shouldRetry $
const $ AppState.flushPool appState >> getConnectionStatus const $ AppState.flushPool appState >> getConnectionStatus
where where