diff options
| author | Paul Oliver <contact@pauloliver.dev> | 2025-01-16 18:26:16 -0800 | 
|---|---|---|
| committer | Paul Oliver <contact@pauloliver.dev> | 2025-01-17 19:16:43 -0800 | 
| commit | dc6bf1472c930ff1448c419d3205148bce1b787e (patch) | |
| tree | be6c1e0544d1e9800b5f65a4e37017f505918f0c /hsm-dummy-fail | |
| parent | e3ea039428545e185b38c5633fe3576ab32f1f8e (diff) | |
Adds error and dummy-fail service
Diffstat (limited to 'hsm-dummy-fail')
| -rw-r--r-- | hsm-dummy-fail/Main.hs | 47 | ||||
| -rw-r--r-- | hsm-dummy-fail/hsm-dummy-fail.cabal | 26 | 
2 files changed, 73 insertions, 0 deletions
| diff --git a/hsm-dummy-fail/Main.hs b/hsm-dummy-fail/Main.hs new file mode 100644 index 0000000..4e293c8 --- /dev/null +++ b/hsm-dummy-fail/Main.hs @@ -0,0 +1,47 @@ +{-# LANGUAGE OverloadedRecordDot #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell #-} + +import Data.Function ((&)) +import Data.Text (Text) +import Effectful (Eff, (:>), runEff) +import Effectful.Concurrent (Concurrent, runConcurrent, threadDelay) +import Effectful.Log (runLog) +import Effectful.Reader.Static (Reader, asks, runReader) +import Effectful.Resource (runResource) +import Hsm.Core.App (launch) +import Hsm.Core.Env (deriveFromYaml) +import Hsm.Core.Zmq.Server (runServer, send) +import Hsm.Status.Error (Error(Error)) +import Streamly.Data.Stream (Stream, fromEffect) +import System.IO.Echo (withoutInputEcho) + +data Env = Env +  { name :: Text +  , pubEp :: Text +  , alive :: Int +  } + +$(deriveFromYaml ''Env) + +singleError :: (Concurrent :> es, Reader Env :> es) => Stream (Eff es) Error +singleError = +  fromEffect $ do +    -- Seemingly, the service needs to be alive for a bit for ZMQ comms to +    -- kick in. +    asks alive >>= threadDelay +    return $ Error 0 "Sent from dummy-fail service" + +-- Dummy fail service: +-- Proof of concept. Publishes a single error that can be catched by a +-- listening client. +main :: IO () +main = +  launch @Env "dummy-fail" withoutInputEcho $ \env logger level -> +    (singleError & send @Env) +      & runServer @Env +      & runConcurrent +      & runLog env.name logger level +      & runReader env +      & runResource +      & runEff diff --git a/hsm-dummy-fail/hsm-dummy-fail.cabal b/hsm-dummy-fail/hsm-dummy-fail.cabal new file mode 100644 index 0000000..269ea9c --- /dev/null +++ b/hsm-dummy-fail/hsm-dummy-fail.cabal @@ -0,0 +1,26 @@ +cabal-version: 3.4 +author:        Paul Oliver +build-type:    Simple +maintainer:    contact@pauloliver.dev +name:          hsm-dummy-fail +version:       0.1.0.0 + +executable dummy-fail +  build-depends: +    , base +    , echo +    , effectful +    , hsm-core +    , hsm-status +    , log-effectful +    , resourcet-effectful +    , streamly-core +    , text + +  main-is:          Main.hs +  ghc-options:      -Wall -Wunused-packages + +  if !arch(x86_64) +    ghc-options: -optl=-mno-fix-cortex-a53-835769 + +  default-language: GHC2021 | 
