@@ -16,8 +16,8 @@ import Control.Exception (finally)
16
16
import qualified Control.Exception as E
17
17
import Control.Monad.Catch (MonadMask , MonadThrow )
18
18
import Control.Monad.Catch.Pure (MonadCatch )
19
+ import Control.Monad.Reader
19
20
import Control.Monad.Trans.Maybe (MaybeT (.. ))
20
- import Control.Monad.Trans.Reader
21
21
import Control.Retry (fibonacciBackoff , limitRetriesByCumulativeDelay , retrying )
22
22
import Data.Aeson hiding ((.=) )
23
23
import qualified Data.Aeson as Aeson
@@ -64,7 +64,16 @@ import Test.Tasty.Providers.ConsoleFormat
64
64
-------------------------------------------------------------------------------
65
65
66
66
newtype App a = App { unApp :: ReaderT Env IO a }
67
- deriving (Functor , Applicative , Monad , MonadIO , MonadMask , MonadCatch , MonadThrow )
67
+ deriving
68
+ ( Functor ,
69
+ Applicative ,
70
+ Monad ,
71
+ MonadIO ,
72
+ MonadMask ,
73
+ MonadCatch ,
74
+ MonadThrow ,
75
+ MonadReader Env
76
+ )
68
77
69
78
data AppFailure = AppFailure String
70
79
@@ -80,12 +89,6 @@ failApp msg = throw (AppFailure msg)
80
89
runAppWithEnv :: Env -> App a -> IO a
81
90
runAppWithEnv e m = runReaderT (unApp m) e
82
91
83
- getContext :: App Context
84
- getContext = App $ asks (. context)
85
-
86
- getManager :: App HTTP. Manager
87
- getManager = App $ asks (. manager)
88
-
89
92
getPrekey :: App Value
90
93
getPrekey = App $ do
91
94
pks <- asks (. prekeys)
@@ -616,10 +619,10 @@ data Versioned = Versioned | Unversioned | ExplicitVersion Int
616
619
617
620
baseRequest :: Service -> Versioned -> String -> App HTTP. Request
618
621
baseRequest service versioned path = do
619
- ctx <- getContext
622
+ ctx <- asks ( . context)
620
623
pathSegsPrefix <- case versioned of
621
624
Versioned -> do
622
- v <- App $ asks (. context. version)
625
+ v <- asks (. context. version)
623
626
pure [" v" <> show v]
624
627
Unversioned -> pure []
625
628
ExplicitVersion v -> do
@@ -632,7 +635,7 @@ baseRequest service versioned path = do
632
635
submit :: String -> HTTP. Request -> App Response
633
636
submit method req0 = do
634
637
let req = req0 {HTTP. method = toByteString' method}
635
- manager <- getManager
638
+ manager <- asks ( . manager)
636
639
res <- liftIO $ HTTP. httpLbs req manager
637
640
pure $
638
641
Response
@@ -813,7 +816,7 @@ withModifiedServices services k = do
813
816
(Map. assocs ports)
814
817
815
818
instances <- for (Map. assocs services) $ \ (srv, modifyConfig) -> do
816
- basedir <- App $ asks (. serviceConfigsDir)
819
+ basedir <- asks (. serviceConfigsDir)
817
820
let srvName = serviceName srv
818
821
cfgFile = basedir </> srvName </> " conf" </> (srvName <> " .yaml" )
819
822
config <- do
@@ -827,11 +830,10 @@ withModifiedServices services k = do
827
830
hClose fh
828
831
829
832
(cwd, exe) <-
830
- App $
831
- asks (. servicesCwdBase) <&> \ case
832
- Nothing -> (Nothing , srvName)
833
- Just dir ->
834
- (Just (dir </> srvName), " ./dist" </> srvName)
833
+ asks (. servicesCwdBase) <&> \ case
834
+ Nothing -> (Nothing , srvName)
835
+ Just dir ->
836
+ (Just (dir </> srvName), " ./dist" </> srvName)
835
837
836
838
(port, socket) <- maybe (failApp " the impossible in withServices happened" ) pure (Map. lookup srv ports)
837
839
liftIO $ N. close socket
0 commit comments