-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fbfe6d
commit 2e80af6
Showing
9 changed files
with
97 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Filter(Filter(..), FilterAction(..), shouldAck) where | ||
|
||
import Message | ||
|
||
data FilterAction = | ||
Ack | ||
| Copy | ||
| CopyAndAck | ||
|
||
shouldAck :: FilterAction -> Bool | ||
shouldAck Copy = False | ||
shouldAck _ = True | ||
|
||
class Filter m where | ||
filterAction :: Message -> m FilterAction | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,35 @@ | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
module Mover(moveMessages) where | ||
|
||
import Destination | ||
import Message | ||
import Source | ||
import Message() | ||
import Filter | ||
|
||
import Control.Monad (unless) | ||
import Control.Monad (unless, void) | ||
|
||
moveMessages :: (Source m, Destination m) => m () | ||
moveMessages = do | ||
stuff | ||
getMessages :: Source m => m (Either NoMessageReason [Message]) | ||
getMessages = do | ||
msg <- receive --todo: should use bulked publish | ||
return $ pure <$> msg | ||
|
||
stuff :: (Source m, Destination m) => m () | ||
stuff = do | ||
maybeMessage <- receive | ||
case maybeMessage of | ||
Left _ -> return () | ||
Right message -> do | ||
publishResult <- publish [message] | ||
let ackable = succeeded publishResult | ||
unless (null ackable) $ acknowledge ackable | ||
stuff | ||
publishAndAckMessages :: forall m.(Source m, Destination m, Filter m) => [Message] -> m () | ||
publishAndAckMessages msgs = void $ traverse publishSingleMessage msgs --todo: should use bulked publish | ||
where publishSingleMessage :: Message -> m () | ||
publishSingleMessage msg = do | ||
publishResult <- publish [msg] | ||
needsAck <- shouldAck <$> (filterAction msg) | ||
if needsAck then do | ||
let ackable = succeeded publishResult | ||
unless (null ackable) $ acknowledge ackable | ||
else return () | ||
|
||
moveMessages :: (Source m, Destination m, Filter m) => m () | ||
moveMessages = do | ||
maybeMessages <- getMessages | ||
case maybeMessages of | ||
Left _ -> return () | ||
Right messages -> do | ||
publishAndAckMessages messages | ||
moveMessages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
- handle exceptions during configmwait | ||
- add logging |