{-# LANGUAGE OverloadedRecordDot #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TemplateHaskell #-} import Data.ByteString (ByteString) 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, ask, runReader) import Effectful.Resource (runResource) import Hsm.Core.App (launch) import Hsm.Core.Env (deriveFromYaml) import Hsm.Core.Message (message) 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) ByteString singleError = fromEffect $ do -- Seemingly, the service needs to be alive for a bit for ZMQ comms to -- kick in. env <- ask @Env threadDelay env.alive return $ message env.name $ 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) & runServer @Env & runConcurrent & runLog env.name logger level & runReader env & runResource & runEff