style/refactor
This commit is contained in:
parent
3a10e3e72c
commit
e2942e38b9
5 changed files with 43 additions and 37 deletions
|
@ -8,8 +8,8 @@ import Data.String.Conversions
|
|||
|
||||
import Network.Wai.Handler.Warp
|
||||
|
||||
import Myriad.Core
|
||||
import Myriad.Config
|
||||
import Myriad.Core
|
||||
import Myriad.Docker
|
||||
import Myriad.Server
|
||||
|
||||
|
|
|
@ -29,25 +29,35 @@ data Language = Language
|
|||
, retries :: Int
|
||||
} deriving (Show)
|
||||
|
||||
readConfig :: FilePath -> IO Config
|
||||
readConfig = fmap fromRawConfig . readRawConfig
|
||||
|
||||
readRawConfig :: FilePath -> IO RawConfig
|
||||
readRawConfig f = do
|
||||
x <- BL.readFile f
|
||||
case decode1 x of
|
||||
Left (pos, e) -> error $ prettyPosWithSource pos x e
|
||||
Right y -> pure y
|
||||
|
||||
fromRawConfig :: RawConfig -> Config
|
||||
fromRawConfig (r@RawConfig { rawLanguages, rawDefaultLanguage }) =
|
||||
fromRawConfig r =
|
||||
Config
|
||||
{ languages = map f rawLanguages
|
||||
{ languages = map (fromRawLanguage $ rawDefaultLanguage r) $ rawLanguages r
|
||||
, buildConcurrently = rawBuildConcurrently r
|
||||
, prepareContainers = rawPrepareContainers r
|
||||
, cleanupInterval = rawCleanupInterval r
|
||||
, port = rawPort r
|
||||
}
|
||||
where
|
||||
f :: RawLanguage -> Language
|
||||
f l =
|
||||
|
||||
fromRawLanguage :: DefaultLanguage -> RawLanguage -> Language
|
||||
fromRawLanguage d l =
|
||||
Language
|
||||
{ name = rawName l
|
||||
, memory = fromMaybe (defMemory rawDefaultLanguage) (rawMemory l)
|
||||
, cpus = fromMaybe (defCpus rawDefaultLanguage) (rawCpus l)
|
||||
, timeout = fromMaybe (defTimeout rawDefaultLanguage) (rawTimeout l)
|
||||
, concurrent = fromMaybe (defConcurrent rawDefaultLanguage) (rawConcurrent l)
|
||||
, retries = fromMaybe (defRetries rawDefaultLanguage) (rawRetries l)
|
||||
, memory = fromMaybe (defMemory d) (rawMemory l)
|
||||
, cpus = fromMaybe (defCpus d) (rawCpus l)
|
||||
, timeout = fromMaybe (defTimeout d) (rawTimeout l)
|
||||
, concurrent = fromMaybe (defConcurrent d) (rawConcurrent l)
|
||||
, retries = fromMaybe (defRetries d) (rawRetries l)
|
||||
}
|
||||
|
||||
data RawConfig = RawConfig
|
||||
|
@ -101,13 +111,3 @@ instance FromYAML RawLanguage where
|
|||
<*> m .:? "timeout"
|
||||
<*> m .:? "concurrent"
|
||||
<*> m .:? "retries"
|
||||
|
||||
readConfig :: FilePath -> IO Config
|
||||
readConfig = fmap fromRawConfig . readRawConfig
|
||||
|
||||
readRawConfig :: FilePath -> IO RawConfig
|
||||
readRawConfig f = do
|
||||
x <- BL.readFile f
|
||||
case decode1 x of
|
||||
Left (pos, e) -> error $ prettyPosWithSource pos x e
|
||||
Right y -> pure y
|
||||
|
|
|
@ -23,8 +23,8 @@ import Control.Exception.Lifted
|
|||
import System.FilePath ((</>))
|
||||
import System.Process.Typed
|
||||
|
||||
import Myriad.Core
|
||||
import Myriad.Config
|
||||
import Myriad.Core
|
||||
|
||||
type Myriad = MyriadT IO
|
||||
|
||||
|
|
|
@ -18,14 +18,20 @@ import Control.Concurrent.Async.Lifted
|
|||
import Control.Concurrent.MVar.Lifted
|
||||
import Servant
|
||||
|
||||
import Myriad.Core
|
||||
import Myriad.Config
|
||||
import Myriad.Core
|
||||
import Myriad.Docker
|
||||
|
||||
type Myriad = MyriadT Handler
|
||||
|
||||
data EvalRequest = EvalRequest { language :: T.Text, code :: String } deriving (Generic, FromJSON)
|
||||
data EvalResponse = EvalResponse { result :: T.Text } deriving (Generic, ToJSON)
|
||||
data EvalRequest = EvalRequest
|
||||
{ language :: T.Text
|
||||
, code :: String
|
||||
} deriving (Generic, FromJSON)
|
||||
|
||||
data EvalResponse = EvalResponse
|
||||
{ result :: T.Text
|
||||
} deriving (Generic, ToJSON)
|
||||
|
||||
type API
|
||||
= "languages" :> Get '[JSON] [T.Text]
|
||||
|
|
Loading…
Reference in a new issue