Skip to content

Commit

Permalink
rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterHajdu committed Nov 15, 2019
1 parent 52c9e4b commit 7ea6f06
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/FileEnv.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ parseRoutingKeyAndMessage line =
(_, "") -> Left $ NMRError "Missing routing key."
(routingK, msg) -> Right $ MkMessage (MkReceiveId 0) (decodeUtf8 routingK) msg

recv :: Handle -> IO (Either NoMessageReason Message)
recv handle = do
readFromFile :: Handle -> IO (Either NoMessageReason Message)
readFromFile handle = do
maybeLine <- catchIO $ BSC.hGetLine handle
let maybeBody = left mapError maybeLine
return $ maybeBody >>= parseRoutingKeyAndMessage
where mapError e = if isEOFError e then NMREmptyQueue else NMRError $ show e

createStdinSource :: SourceFunctions
createStdinSource = MkSourceFunctions (recv stdin) (const $ return ())
createStdinSource = MkSourceFunctions (readFromFile stdin) (const $ return ())

createFileSource :: FilePath -> IO (Either String SourceFunctions)
createFileSource filePath = do
maybeHandle <- catchIO $ openFile filePath ReadMode
return $ bimap show (\handle -> MkSourceFunctions (recv 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 Down
2 changes: 1 addition & 1 deletion todo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- add logging
- add scriptfilter
- add logging
- extract bulk size to config

to be decided:
Expand Down

0 comments on commit 7ea6f06

Please sign in to comment.