[refactor] <&> refactoring

parent 1dd92f0a
...@@ -45,6 +45,7 @@ where ...@@ -45,6 +45,7 @@ where
-- import Control.Exception (Exception, SomeException(..), catch, fromException, throwIO, toException) -- import Control.Exception (Exception, SomeException(..), catch, fromException, throwIO, toException)
import Control.Monad (void) import Control.Monad (void)
import Data.Functor ((<&>))
import Data.String (fromString) import Data.String (fromString)
import Data.Text qualified as T import Data.Text qualified as T
import Database.PGMQ.Schema (pgmqSchema) import Database.PGMQ.Schema (pgmqSchema)
...@@ -129,7 +130,7 @@ dropQueue conn queue = ...@@ -129,7 +130,7 @@ dropQueue conn queue =
https://tembo.io/pgmq/api/sql/functions/#metrics -} https://tembo.io/pgmq/api/sql/functions/#metrics -}
getMetrics :: PSQL.Connection -> Queue -> IO (Maybe Metrics) getMetrics :: PSQL.Connection -> Queue -> IO (Maybe Metrics)
getMetrics conn queue = getMetrics conn queue =
PSQL.query conn [sql| SELECT * FROM pgmq.metrics(?) |] (PSQL.Only queue) >>= return . headMay PSQL.query conn [sql| SELECT * FROM pgmq.metrics(?) |] (PSQL.Only queue) <&> headMay
-- catch -- catch
-- (PSQL.query conn [sql| SELECT * FROM pgmq.metrics(?) |] (PSQL.Only queue) >>= return . headMay) -- (PSQL.query conn [sql| SELECT * FROM pgmq.metrics(?) |] (PSQL.Only queue) >>= return . headMay)
-- handleError -- handleError
...@@ -189,7 +190,7 @@ purgeQueue conn queue = do ...@@ -189,7 +190,7 @@ purgeQueue conn queue = do
readMessage :: (SerializableMessage a) readMessage :: (SerializableMessage a)
=> PSQL.Connection -> Queue -> VisibilityTimeout -> IO (Maybe (Message a)) => PSQL.Connection -> Queue -> VisibilityTimeout -> IO (Maybe (Message a))
readMessage conn queue vt = readMessage conn queue vt =
readMessages conn queue vt 1 >>= return . headMay readMessages conn queue vt 1 <&> headMay
-- | Read a message from given archive -- | Read a message from given archive
readMessageFromArchive :: (SerializableMessage a) readMessageFromArchive :: (SerializableMessage a)
...@@ -198,7 +199,7 @@ readMessageFromArchive conn queue msgId = do ...@@ -198,7 +199,7 @@ readMessageFromArchive conn queue msgId = do
let archiveTable = "a_" <> queue let archiveTable = "a_" <> queue
PSQL.query conn PSQL.query conn
[sql| SELECT msg_id, read_ct, enqueued_at, archived_at, vt, message FROM ? WHERE msg_id = ?|] [sql| SELECT msg_id, read_ct, enqueued_at, archived_at, vt, message FROM ? WHERE msg_id = ?|]
(PSQL.QualifiedIdentifier (Just "pgmq") $ T.pack archiveTable, msgId) >>= return . headMay (PSQL.QualifiedIdentifier (Just "pgmq") $ T.pack archiveTable, msgId) <&> headMay
-- | Read a message from queue with given ID (for querying purposes, doesn't pop message from queue) -- | Read a message from queue with given ID (for querying purposes, doesn't pop message from queue)
readMessageById :: (SerializableMessage a) readMessageById :: (SerializableMessage a)
...@@ -207,7 +208,7 @@ readMessageById conn queue msgId = do ...@@ -207,7 +208,7 @@ readMessageById conn queue msgId = do
let queueTable = "q_" <> queue let queueTable = "q_" <> queue
PSQL.query conn PSQL.query conn
[sql| SELECT msg_id, read_ct, enqueued_at, NULL, vt, message FROM ? WHERE msg_id = ?|] [sql| SELECT msg_id, read_ct, enqueued_at, NULL, vt, message FROM ? WHERE msg_id = ?|]
(PSQL.QualifiedIdentifier (Just "pgmq") $ T.pack queueTable, msgId) >>= return . headMay (PSQL.QualifiedIdentifier (Just "pgmq") $ T.pack queueTable, msgId) <&> headMay
{-| Reads given number of messages from given queue {-| Reads given number of messages from given queue
...@@ -233,7 +234,7 @@ readMessageWithPoll :: (SerializableMessage a) ...@@ -233,7 +234,7 @@ readMessageWithPoll :: (SerializableMessage a)
-> PollIntervalMs -> PollIntervalMs
-> IO (Maybe (Message a)) -> IO (Maybe (Message a))
readMessageWithPoll conn queue vt maxPollSeconds pollIntervalMs = readMessageWithPoll conn queue vt maxPollSeconds pollIntervalMs =
readMessagesWithPoll conn queue vt 1 maxPollSeconds pollIntervalMs >>= return . headMay readMessagesWithPoll conn queue vt 1 maxPollSeconds pollIntervalMs <&> headMay
-- | Reads given number of messages, polling for given duration if the -- | Reads given number of messages, polling for given duration if the
-- queue is empty. -- queue is empty.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment