Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

[chain-index]: start a web server with forkProcess instead of withAsync #382

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plutus-chain-index/plutus-chain-index.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ library
stm -any,
time-units -any,
yaml -any,
unix -any

executable plutus-chain-index
main-is: Main.hs
Expand Down
23 changes: 11 additions & 12 deletions plutus-chain-index/src/Plutus/ChainIndex/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
-}
module Plutus.ChainIndex.App(main, runMain) where

import Cardano.BM.Configuration.Model qualified as CM
import Control.Exception (throwIO)
import Control.Monad (void)
import Data.Aeson qualified as A
import Data.Foldable (for_)
import Data.Function ((&))
import Data.Yaml qualified as Y
import Options.Applicative (execParser)
import Prettyprinter (Pretty (pretty))

import Cardano.BM.Configuration.Model qualified as CM
import System.Posix.Process (forkProcess)

import Cardano.BM.Setup (setupTrace_)
import Cardano.BM.Trace (Trace)
Expand Down Expand Up @@ -73,6 +74,13 @@ runMain :: CM.Configuration -> Config.ChainIndexConfig -> IO ()
runMain logConfig config = do
withRunRequirements logConfig config $ \runReq -> do

void $ forkProcess $ do
let port = show (Config.cicPort config)
putStrLn $ "Starting webserver on port " <> port
putStrLn $ "A Swagger UI for the endpoints are available at "
<> "http://localhost:" <> port <> "/swagger/swagger-ui"
Server.serveChainIndexQueryServer (Config.cicPort config) runReq

putStr "\nThe tip of the local node: "
slotNo <- getTipSlot config
print slotNo
Expand All @@ -83,17 +91,8 @@ runMain logConfig config = do
<- storeChainSyncHandler eventsQueue
& storeFromBlockNo (fromCardanoBlockNo $ Config.cicStoreFrom config)
& pure

putStrLn $ "Connecting to the node using socket: " <> Config.cicSocketPath config
syncChainIndex config runReq syncHandler

(trace :: Trace IO (PrettyObject SyncLog), _) <- setupTrace_ logConfig "chain-index"
withAsync (processEventsQueue trace runReq eventsQueue) $ \processAsync -> do

let port = show (Config.cicPort config)
putStrLn $ "Starting webserver on port " <> port
putStrLn $ "A Swagger UI for the endpoints are available at "
<> "http://localhost:" <> port <> "/swagger/swagger-ui"
Server.serveChainIndexQueryServer (Config.cicPort config) runReq
wait processAsync

withAsync (processEventsQueue trace runReq eventsQueue) wait