aboutsummaryrefslogtreecommitdiff
path: root/hsm-dummy-pulser
diff options
context:
space:
mode:
Diffstat (limited to 'hsm-dummy-pulser')
-rw-r--r--hsm-dummy-pulser/Main.hs30
-rw-r--r--hsm-dummy-pulser/hsm-dummy-pulser.cabal1
2 files changed, 14 insertions, 17 deletions
diff --git a/hsm-dummy-pulser/Main.hs b/hsm-dummy-pulser/Main.hs
index d15b616..cc16cd4 100644
--- a/hsm-dummy-pulser/Main.hs
+++ b/hsm-dummy-pulser/Main.hs
@@ -2,6 +2,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
+import Data.ByteString (ByteString)
import Data.Function ((&))
import Data.Text (Text, pack)
import Effectful (Eff, (:>), runEff)
@@ -13,6 +14,7 @@ import Effectful.State.Static.Local (evalState)
import Hsm.Core.App (launch)
import Hsm.Core.Env (deriveFromYaml)
import Hsm.Core.Fsm qualified as F
+import Hsm.Core.Message (message)
import Hsm.Core.Zmq.Server (runServer, send)
import Streamly.Data.Stream (Stream, repeatM)
import System.IO.Echo (withoutInputEcho)
@@ -29,29 +31,23 @@ $(deriveFromYaml ''Env)
pulse :: (Concurrent :> es, Reader Env :> es) => Stream (Eff es) ()
pulse = repeatM $ asks period >>= threadDelay
-stateRun :: F.FsmState () Int Env Int
-stateRun = F.FsmState "run" action
- where
- action _ env sta =
- if sta < env.pulses
- then next
- else exit
- where
- next =
- F.FsmOutput
- (Just $ F.FsmResult sta (succ sta) stateRun)
- [(LogInfo, "Sending pulse #" <> pack (show sta))]
- exit =
- F.FsmOutput
- Nothing
- [(LogAttention, "Reached " <> pack (show env.pulses) <> " pulses")]
+stateRun :: F.FsmState () ByteString Env Int
+stateRun =
+ F.FsmState "run" $ \_ env sta ->
+ if sta < env.pulses
+ then F.FsmOutput
+ (Just $ F.FsmResult (message env.name sta) (succ sta) stateRun)
+ [(LogInfo, "Sending pulse #" <> pack (show sta))]
+ else F.FsmOutput
+ Nothing
+ [(LogAttention, "Sent " <> pack (show env.pulses) <> " pulses")]
-- Dummy pulser service:
-- Proof of concept. Publishes a "pulse" through ZMQ at a set interval.
main :: IO ()
main =
launch @Env "dummy-pulser" withoutInputEcho $ \env logger level ->
- (pulse & F.fsm @_ @_ @Env @Int & send @Env @_ @Int)
+ (pulse & F.fsm @_ @_ @Env @Int & send)
& runServer @Env
& evalState @Int 1
& evalState stateRun
diff --git a/hsm-dummy-pulser/hsm-dummy-pulser.cabal b/hsm-dummy-pulser/hsm-dummy-pulser.cabal
index 747f62c..428c139 100644
--- a/hsm-dummy-pulser/hsm-dummy-pulser.cabal
+++ b/hsm-dummy-pulser/hsm-dummy-pulser.cabal
@@ -8,6 +8,7 @@ version: 0.1.0.0
executable dummy-pulser
build-depends:
, base
+ , bytestring
, echo
, effectful
, hsm-core