Skip to content

Instantly share code, notes, and snippets.

@lorenzo
Created July 28, 2017 13:20
Show Gist options
  • Save lorenzo/7d3a4cc983eb99651cee532d9cfc34fb to your computer and use it in GitHub Desktop.
Save lorenzo/7d3a4cc983eb99651cee532d9cfc34fb to your computer and use it in GitHub Desktop.
import qualified Control.Distributed.Process as Process
data Config = Config
{ uiPort :: Int
, dbType :: DbBackend
, folder :: String
, testsList :: Scheduler.RunSchedule
}
newtype App a = App
{ runApp :: ReaderT Config Process.Process a
} deriving (Monad, Functor, Applicative, MonadIO)
mainProcess config = do
port <- readPort "WRECKER_PORT" 10500
backend <- LocalNet.initializeBackend "127.0.0.1" (show @Int port) Node.initRemoteTable
LocalNet.startMaster backend $ \slaves -> do runReaderT (runApp (startUI backend slaves)) config
getConfig :: IO Config
getConfig = do
uiPort <- readPort "WRECKER_UI_PORT" 3000
dbType <- selectDatabaseType
folder <- findAssetsFolder
testsList <- Scheduler.emptyRunSchedule
return (Config {..})
startUI :: LocalNet.Backend -> [NodeId] -> App ()
startUI backend slaves = do
self <- Process.getSelfPid -- Oops... cannot match App with Process.Process
liftIO $ do
putStrLn $ show self
putStrLn ("Slaves: " ++ show slaves)
withDb dbType $ \db ->
liftIO $ -- We're inside the DbMonad, so the results needs to be converted back to IO
do
runMigrations db
scheduler <- async (Scheduler.runScheduler db testsList)
link scheduler
routes uiPort folder db testsList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment