From 926d001a9bd17890343b792e6867934112655d6f Mon Sep 17 00:00:00 2001 From: Peter Hajdu Date: Fri, 15 May 2020 11:22:03 +0200 Subject: [PATCH] use text instead of string in nmrerror --- lib/Bobek/Mover.hs | 17 ++++++++--------- lib/Bobek/Source.hs | 9 ++++++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/Bobek/Mover.hs b/lib/Bobek/Mover.hs index 0f40484..1c73af3 100644 --- a/lib/Bobek/Mover.hs +++ b/lib/Bobek/Mover.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE ScopedTypeVariables #-} - module Bobek.Mover ( moveMessages, ) @@ -13,7 +11,7 @@ import Bobek.ReceiveId import Bobek.Source import Data.Set () import qualified Data.Set as Set -import qualified Data.Text as T (concat, pack) +import qualified Data.Text as T (concat) bulkSize :: Int bulkSize = 1000 @@ -22,7 +20,7 @@ getMessages :: (Logger m, Source m) => m (Maybe [Message]) getMessages = do maybeMessages <- replicateM bulkSize receive let (errors, messages) = partitionEithers maybeMessages - traverse_ (\msg -> logError $ T.concat ["Failed to read message: ", T.pack . show $ msg]) errors + traverse_ (logError . reasonText) errors return $ if null messages then Nothing @@ -48,7 +46,8 @@ publishMessages msgs = then return Set.empty else Set.fromList . succeeded <$> publish msgs -publishAndAckMessages :: forall m. (Logger m, Source m, Destination m, Filter m) => [Message] -> m () +--todo: remove forall and extension +publishAndAckMessages :: (Logger m, Source m, Destination m, Filter m) => [Message] -> m () publishAndAckMessages msgs = do actionsWithMessage <- runFilter msgs let (needsAck, needsPublish, doesNotNeedPublish) = splitUpMessagesByAction actionsWithMessage @@ -59,13 +58,13 @@ publishAndAckMessages msgs = do logDebug $ T.concat [ " needsPublish: ", - T.pack . show . length $ needsPublish, + show . length $ needsPublish, " published: ", - T.pack . show . length $ publishedIds, + show . length $ publishedIds, " needsAck: ", - T.pack . show . length $ needsAck, + show . length $ needsAck, " acked: ", - T.pack . show . length $ toBeAcked + show . length $ toBeAcked ] return () diff --git a/lib/Bobek/Source.hs b/lib/Bobek/Source.hs index 8502e82..9f79ee9 100644 --- a/lib/Bobek/Source.hs +++ b/lib/Bobek/Source.hs @@ -1,12 +1,15 @@ -module Bobek.Source (Source (..), NoMessageReason (..)) where +module Bobek.Source (reasonText, Source (..), NoMessageReason (..)) where import Bobek.Message (Message) import Bobek.ReceiveId (ReceiveId) data NoMessageReason - = NMRError String + = NMRError Text | NMREmptyQueue - deriving stock (Show) + +reasonText :: NoMessageReason -> Text +reasonText (NMRError msg) = msg +reasonText NMREmptyQueue = "Empty queue." class Monad m => Source m where receive :: m (Either NoMessageReason Message)