summaryrefslogtreecommitdiff
path: root/hsm-dummy-receiver
diff options
context:
space:
mode:
Diffstat (limited to 'hsm-dummy-receiver')
-rw-r--r--hsm-dummy-receiver/Main.hs46
-rw-r--r--hsm-dummy-receiver/hsm-dummy-receiver.cabal21
2 files changed, 67 insertions, 0 deletions
diff --git a/hsm-dummy-receiver/Main.hs b/hsm-dummy-receiver/Main.hs
new file mode 100644
index 0000000..37e99b8
--- /dev/null
+++ b/hsm-dummy-receiver/Main.hs
@@ -0,0 +1,46 @@
+{-# LANGUAGE OverloadedRecordDot #-}
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE TemplateHaskell #-}
+
+module Main
+ ( main
+ )
+where
+
+import Data.Aeson.TH (defaultOptions, deriveFromJSON, rejectUnknownFields)
+import Data.Function ((&))
+import Data.Text (Text, show)
+import Effectful (Eff, runEff, (:>))
+import Effectful.Log (Log, localDomain, logInfo_, runLog)
+import Effectful.Reader.Static (runReader)
+import Effectful.Resource (runResource)
+import Hsm.Core.App (launch)
+import Hsm.Core.Zmq (receive, runClient)
+import Streamly.Data.Fold (drain)
+import Streamly.Data.Stream (fold, mapM, repeatM)
+import Prelude hiding (mapM, show)
+
+data Env = Env
+ { name :: Text
+ , subEps :: [Text]
+ , topics :: [Text]
+ }
+
+$(deriveFromJSON defaultOptions {rejectUnknownFields = True} ''Env)
+
+receiver :: Log :> es => Int -> Eff es ()
+receiver =
+ localDomain "receiver"
+ . logInfo_
+ . mappend "Received pulse #"
+ . show
+
+main :: IO ()
+main =
+ launch @Env "dummy-receiver" $ \env logger level ->
+ (repeatM receive & mapM receiver & fold drain)
+ & runClient @Env
+ & runLog env.name logger level
+ & runReader env
+ & runResource
+ & runEff
diff --git a/hsm-dummy-receiver/hsm-dummy-receiver.cabal b/hsm-dummy-receiver/hsm-dummy-receiver.cabal
new file mode 100644
index 0000000..ab12089
--- /dev/null
+++ b/hsm-dummy-receiver/hsm-dummy-receiver.cabal
@@ -0,0 +1,21 @@
+cabal-version: 3.4
+author: Paul Oliver
+build-type: Simple
+maintainer: contact@pauloliver.dev
+name: hsm-dummy-receiver
+version: 0.1.0.0
+
+executable dummy-receiver
+ build-depends:
+ , aeson
+ , base
+ , effectful-core
+ , hsm-core
+ , log-effectful
+ , resourcet-effectful
+ , streamly-core
+ , text
+
+ main-is: Main.hs
+ ghc-options: -Wall -Wunused-packages
+ default-language: GHC2024