fix: log on LISTEN notification

This commit is contained in:
steve-chavez
2024-03-19 13:22:51 +03:30
committed by Steve Chavez
parent 47b70b8329
commit ee8b3ef8fe
4 changed files with 17 additions and 7 deletions
+7 -5
View File
@@ -1,4 +1,5 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
@@ -501,6 +502,7 @@ listener appState observer = do
putIsListenerOn appState True
SQL.listen db $ SQL.toPgIdentifier dbChannel
SQL.waitForNotifications handleNotification db
Left err -> do
observer $ DBListenerFail dbChannel err
exitFailure
@@ -517,11 +519,11 @@ listener appState observer = do
-- retry the listener
listener appState observer
handleNotification _ msg
| BS.null msg = cacheReloader
| msg == "reload schema" = cacheReloader
| msg == "reload config" = reReadConfig False appState observer
| otherwise = pure () -- Do nothing if anything else than an empty message is sent
handleNotification channel msg =
if | BS.null msg -> observer (DBListenerGotSCacheMsg channel) >> cacheReloader
| msg == "reload schema" -> observer (DBListenerGotSCacheMsg channel) >> cacheReloader
| msg == "reload config" -> observer (DBListenerGotConfigMsg channel) >> reReadConfig False appState observer
| otherwise -> pure () -- Do nothing if anything else than an empty message is sent
cacheReloader =
-- reloads the schema cache + restarts pool connections
+7 -1
View File
@@ -40,6 +40,8 @@ data Observation
| DBListenerStart Text
| DBListenerFail Text SQL.ConnectionError
| DBListenerFailRecoverObs Bool Text (Either SomeException ())
| DBListenerGotSCacheMsg ByteString
| DBListenerGotConfigMsg ByteString
| ConfigReadErrorObs
| ConfigReadErrorFatalObs SQL.UsageError Text
| ConfigReadErrorNotFatalObs SQL.UsageError
@@ -82,11 +84,15 @@ observationMessage = \case
ConnectionPgVersionErrorObs usageErr ->
jsonMessage usageErr
DBListenerStart channel -> do
"Listening for notifications on the " <> channel <> " channel"
"Listening for notifications on the " <> show channel <> " channel"
DBListenerFail channel err -> do
"Could not listen for notifications on the " <> channel <> " channel. " <> show err
DBListenerFailRecoverObs recover channel err ->
"Could not listen for notifications on the " <> channel <> " channel. " <> showListenerError err <> (if recover then " Retrying listening for notifications.." else mempty)
DBListenerGotSCacheMsg channel ->
"Received a schema cache reload message on the " <> show channel <> " channel"
DBListenerGotConfigMsg channel ->
"Received a config reload message on the " <> show channel <> " channel"
ConfigReadErrorObs ->
"An error ocurred when trying to query database settings for the config parameters"
ConfigReadErrorFatalObs usageErr hint ->