on master help sign in
Delay getting port or assets until right before the

In Obelisk.Command.Run, we need to get port and assets to start the server. But these values could change so we want to delay getting them until right before we actually run the server, potentially avoiding race conditions.

commit491697105f936d47fbeecb82cdc203a2c5ee911a authorMatthew Bauer <mjbauer95@gmail.com> dateWed 12 Feb 2020, 14:33 (7 years ago) parent673c796
1 file changed+13−14
lib/command/src/Obelisk/Command/Run.hs+13−14
lib/command/src/Obelisk/Command/Run.hs+13−14
@@ -84,9 +84,6 @@ profile
8484 => FilePath
8585 -> m ()
8686profile profileBaseName = withProjectRoot "." $ \root -> do
87− freePort <- getFreePort
88− assets <- findProjectAssets root
89− putLog Debug $ "Assets impurely loaded from: " <> assets
9087 putLog Debug "Using profiled build of project."
9188 liftIO $ createDirectoryIfMissing False $ takeDirectory profileBaseName
9289 let -- Sane flags to enable by default, enable time profiling +
@@ -113,6 +110,9 @@ profile profileBaseName = withProjectRoot "." $ \root -> do
113110 { _target_path = Nothing
114111 , _target_attr = Nothing
115112 , _target_expr = Just nixBuildExpr }
113+ assets <- findProjectAssets root
114+ putLog Debug $ "Assets impurely loaded from: " <> assets
115+ freePort <- getFreePort
116116 (_, _, _, ph) <- createProcess_ "runProfExe" $ setCwd (Just root) $ setDelegateCtlc True $ proc exePath ([show freePort, T.unpack assets] <> rtsFlags)
117117 _ <- liftIO $ waitForProcess ph
118118 pure ()
@@ -122,18 +122,17 @@ run
122122 => m ()
123123run = withProjectRoot "." $ \root -> do
124124 pkgs <- fmap toList . parsePackagesOrFail =<< getLocalPkgs root
125− freePort <- getFreePort
126− assets <- findProjectAssets root
127− putLog Debug $ "Assets impurely loaded from: " <> assets
128− let obRunExpr = unwords
129− [ "Obelisk.Run.run"
130− , show freePort
131− , "(Obelisk.Run.runServeAsset " ++ show assets ++ ")"
132− , "Backend.backend"
133− , "Frontend.frontend"
134− ]
135125 withGhciScript pkgs root $ \dotGhciPath -> do
136− runGhcid root True dotGhciPath pkgs $ Just obRunExpr
126+ freePort <- getFreePort
127+ assets <- findProjectAssets root
128+ putLog Debug $ "Assets impurely loaded from: " <> assets
129+ runGhcid root True dotGhciPath pkgs $ Just $ unwords
130+ [ "Obelisk.Run.run"
131+ , show freePort
132+ , "(Obelisk.Run.runServeAsset " ++ show assets ++ ")"
133+ , "Backend.backend"
134+ , "Frontend.frontend"
135+ ]
137136
138137runRepl :: MonadObelisk m => m ()
139138runRepl = withProjectRoot "." $ \root -> do