Skip to content

Commit

Permalink
use text instead of string in nmrerror
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterHajdu committed May 15, 2020
1 parent 9acfaba commit 926d001
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
17 changes: 8 additions & 9 deletions lib/Bobek/Mover.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{-# LANGUAGE ScopedTypeVariables #-}

module Bobek.Mover
( moveMessages,
)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 ()

Expand Down
9 changes: 6 additions & 3 deletions lib/Bobek/Source.hs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 926d001

Please sign in to comment.