Skip to content

Commit

Permalink
remove tshow
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterHajdu committed May 15, 2020
1 parent 503dea8 commit 9acfaba
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 16 deletions.
1 change: 0 additions & 1 deletion bobek.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ library
Bobek.OptParse
Bobek.Env
Bobek.Log
other-modules: Bobek.Util

test-suite test
main-is: Test.hs
Expand Down
5 changes: 2 additions & 3 deletions lib/Bobek/FileEnv.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Bobek.Env (SourceFunctions (..))
import Bobek.Message
import Bobek.ReceiveId
import Bobek.Source
import Bobek.Util (tshow)
import Control.Arrow (left)
import Control.Exception (IOException, try)
import qualified Data.ByteString.Char8 as BSC (ByteString, append, cons, hGetLine, hPutStrLn, span)
Expand Down Expand Up @@ -39,7 +38,7 @@ createStdinSource = MkSourceFunctions (readFromFile stdin) (const $ return ())
createFileSource :: FilePath -> IO (Either T.Text SourceFunctions)
createFileSource filePath = do
maybeHandle <- catchIO $ openFile filePath ReadMode
return $ bimap tshow (\handle -> MkSourceFunctions (readFromFile handle) (const $ return ())) maybeHandle
return $ bimap show (\handle -> MkSourceFunctions (readFromFile handle) (const $ return ())) maybeHandle

serializeMessage :: Message -> BSC.ByteString
serializeMessage (MkMessage _ routingK msg) = encodeUtf8 routingK `BSC.append` BSC.cons routingKeySeparator msg
Expand All @@ -59,7 +58,7 @@ writeToFile handle messages = do
createFileDestination :: FilePath -> IO (Either T.Text ([Message] -> IO PublishResult))
createFileDestination filePath = do
maybeHandle <- catchIO $ openFile filePath AppendMode
return $ bimap tshow writeToFile maybeHandle
return $ bimap show writeToFile maybeHandle

createStdoutDestination :: [Message] -> IO PublishResult
createStdoutDestination = writeToFile stdout
11 changes: 5 additions & 6 deletions lib/Bobek/RabbitMqEnv.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Bobek.Env (SourceFunctions (..))
import qualified Bobek.Message as M
import Bobek.ReceiveId
import Bobek.Source
import Bobek.Util (tshow)
import Control.Arrow (left)
import Control.Exception (try)
import Control.Monad.Trans.Except (except)
Expand Down Expand Up @@ -65,19 +64,19 @@ rabbitAcknowledge channel = traverse_ ackMessage
createChannel :: AMQP.ConnectionOpts -> IO (Either T.Text AMQP.Channel)
createChannel connOpts = runExceptT $ do
maybeConn <- liftIO $ catchAmqp $ AMQP.openConnection'' connOpts
conn <- except $ left tshow maybeConn
conn <- except $ left show maybeConn
maybeChan <- liftIO $ catchAmqp $ AMQP.openChannel conn
except $ left tshow maybeChan
except $ left show maybeChan

createRabbitMqSource :: AMQP.ConnectionOpts -> T.Text -> IO (Either T.Text SourceFunctions)
createRabbitMqSource connOpts queue = do
maybeChan <- createChannel connOpts
return $ bimap tshow (\chan -> MkSourceFunctions (rabbitReceive chan queue) (rabbitAcknowledge chan)) maybeChan
return $ bimap show (\chan -> MkSourceFunctions (rabbitReceive chan queue) (rabbitAcknowledge chan)) maybeChan

createRabbitMqDestination :: AMQP.ConnectionOpts -> T.Text -> Maybe T.Text -> IO (Either T.Text ([M.Message] -> IO PublishResult))
createRabbitMqDestination connOpts exchange routingKey = runExceptT $ do
maybeChan <- liftIO $ createChannel connOpts
channel <- except $ left tshow maybeChan
channel <- except $ left show maybeChan
mightFail <- liftIO $ catchAmqp $ AMQP.confirmSelect channel False
except $ left tshow mightFail
except $ left show mightFail
return $ rabbitPublish channel exchange routingKey
6 changes: 0 additions & 6 deletions lib/Bobek/Util.hs

This file was deleted.

1 change: 1 addition & 0 deletions todo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
TODO unit tests for: Env.hs, FileEnv.hs, OptParse.hs, RabbitMqEnv.hs
TODO fix script filter protocol (length of message in first line, json?, base64)
TODO use phantom type parameter to track published state of messages
TODO extract bulk size to config
Expand Down

0 comments on commit 9acfaba

Please sign in to comment.