Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SCP-5012 Migrated
marlowe-pipe
from marlowe-lambda repo.
- Loading branch information
Showing
3 changed files
with
79 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
|
||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
|
||
module Main | ||
( main | ||
) where | ||
|
||
|
||
import Control.Monad.Except (liftIO, runExceptT) | ||
import Data.Aeson (eitherDecode, encode) | ||
import Data.Text (Text) | ||
import Language.Marlowe.Runtime.App.Parser (getConfigParser) | ||
import Language.Marlowe.Runtime.App.Transact (handleWithEvents) | ||
import Observe.Event (addField, hoistEvent, withEvent) | ||
import Observe.Event.Dynamic (DynamicEventSelector(..)) | ||
import Observe.Event.Render.JSON (DefaultRenderSelectorJSON(defaultRenderSelectorJSON)) | ||
import Observe.Event.Render.JSON.Handle (simpleJsonStderrBackend) | ||
import Observe.Event.Syntax ((≔)) | ||
|
||
import qualified Data.ByteString.Lazy.Char8 as LBS8 (getContents, lines, putStrLn, unpack) | ||
import qualified Options.Applicative as O | ||
|
||
|
||
main :: IO () | ||
main = | ||
do | ||
configParser <- getConfigParser | ||
config <- | ||
O.execParser | ||
$ O.info | ||
(O.helper {- <*> O.versionOption -} <*> configParser) | ||
( | ||
O.fullDesc | ||
<> O.progDesc "This command-line tool reads lines of JSON from standard input, interpets them as Marlowe App requests, executes them, and prints the response JSON on standard output." | ||
<> O.header "marlowe-pipe: run marlowe application requests" | ||
) | ||
eventBackend <- simpleJsonStderrBackend defaultRenderSelectorJSON | ||
requests <- LBS8.lines <$> LBS8.getContents | ||
sequence_ | ||
[ | ||
withEvent eventBackend (DynamicEventSelector "MarloweApp") | ||
$ \event -> | ||
do | ||
addField event $ ("line" :: Text) ≔ LBS8.unpack line | ||
case eitherDecode line of | ||
Right request -> runExceptT (handleWithEvents (hoistEvent liftIO event) "Handle" config request pure) | ||
>>= \case | ||
Right response -> LBS8.putStrLn $ encode response | ||
Left message -> LBS8.putStrLn $ encode message | ||
Left message -> LBS8.putStrLn $ encode message | ||
| | ||
line <- requests | ||
] |
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