Skip to content

Commit

Permalink
Add healthcheck to marlowe-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
jhbertra committed Mar 16, 2023
1 parent ad89fd9 commit b2f2f8d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion marlowe-runtime/marlowe-sync/Main.hs
Expand Up @@ -49,7 +49,7 @@ main :: IO ()
main = run =<< getOptions

run :: Options -> IO ()
run Options{..} = bracket (Pool.acquire 100 (Just $ 5000000) (fromString databaseUri)) Pool.release $
run Options{..} = bracket (Pool.acquire 100 (Just 5000000) (fromString databaseUri)) Pool.release $
runComponent_ proc pool -> do
eventBackend <- logger -< LoggerDependencies
{ configFilePath = logConfigFile
Expand Down Expand Up @@ -90,6 +90,7 @@ run Options{..} = bracket (Pool.acquire 100 (Just $ 5000000) (fromString databas
, querySource = SomeConnectionSource
$ logConnectionSource (narrowEventBackend (injectSelector MarloweQueryServer) eventBackend)
$ handshakeConnectionSource querySource
, httpPort = fromIntegral httpPort
}
where
throwUsageError (ConnectionUsageError err) = error $ show err
Expand All @@ -104,6 +105,7 @@ data Options = Options
, queryPort :: PortNumber
, host :: HostName
, logConfigFile :: Maybe FilePath
, httpPort :: PortNumber
}

getOptions :: IO Options
Expand All @@ -116,6 +118,7 @@ getOptions = execParser $ info (helper <*> parser) infoMod
<*> queryPort
<*> hostParser
<*> logConfigFileParser
<*> httpPortParser

databaseUriParser = strOption $ mconcat
[ long "database-uri"
Expand Down Expand Up @@ -163,6 +166,14 @@ getOptions = execParser $ info (helper <*> parser) infoMod
, help "The logging configuration JSON file."
]

httpPortParser = option auto $ mconcat
[ long "http-port"
, metavar "PORT_NUMBER"
, help "Port number to serve the http healthcheck API on"
, value 8080
, showDefault
]

infoMod = mconcat
[ fullDesc
, progDesc "Contract synchronization and query service for Marlowe Runtime"
Expand Down
10 changes: 10 additions & 0 deletions marlowe-runtime/sync/Language/Marlowe/Runtime/Sync.hs
Expand Up @@ -4,6 +4,7 @@ module Language.Marlowe.Runtime.Sync
where

import Control.Concurrent.Component
import Control.Concurrent.Component.Probes
import Language.Marlowe.Protocol.HeaderSync.Server (MarloweHeaderSyncServer)
import Language.Marlowe.Protocol.Query.Server (MarloweQueryServer)
import Language.Marlowe.Protocol.Sync.Server (MarloweSyncServer)
Expand All @@ -18,10 +19,19 @@ data SyncDependencies = SyncDependencies
, syncSource :: SomeConnectionSource MarloweSyncServer IO
, headerSyncSource :: SomeConnectionSource MarloweHeaderSyncServer IO
, querySource :: SomeConnectionSource MarloweQueryServer IO
, httpPort :: Int
}

sync :: Component IO SyncDependencies ()
sync = proc SyncDependencies{..} -> do
marloweSyncServer -< MarloweSyncServerDependencies{..}
marloweHeaderSyncServer -< MarloweHeaderSyncServerDependencies{..}
queryServer -< QueryServerDependencies{..}
probeServer -< ProbeServerDependencies
{ probes = Probes
{ startup = pure True
, liveness = pure True
, readiness = pure True
}
, port = httpPort
}

0 comments on commit b2f2f8d

Please sign in to comment.