From 654edd780dfd28b3611e42df9fd7fd68b8f88191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Fri, 10 Jan 2025 22:21:14 +0100 Subject: Limit number of concurrently running jobs Changelog: Configurable number of concurrently running jobs --- src/Command.hs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/Command.hs') diff --git a/src/Command.hs b/src/Command.hs index 0ca6710..2c2235f 100644 --- a/src/Command.hs +++ b/src/Command.hs @@ -1,8 +1,12 @@ module Command ( + CommonOptions(..), + defaultCommonOptions, + Command(..), CommandArgumentsType(..), CommandExec(..), + getCommonOptions, getConfig, ) where @@ -17,6 +21,15 @@ import System.Console.GetOpt import Config +data CommonOptions = CommonOptions + { optJobs :: Int + } + +defaultCommonOptions :: CommonOptions +defaultCommonOptions = CommonOptions + { optJobs = 2 + } + class CommandArgumentsType (CommandArguments c) => Command c where commandName :: proxy c -> String commandDescription :: proxy c -> String @@ -54,8 +67,11 @@ instance CommandArgumentsType (Maybe Text) where argsFromStrings _ = throwError "expected at most one argument" -newtype CommandExec a = CommandExec (ReaderT Config IO a) +newtype CommandExec a = CommandExec (ReaderT ( CommonOptions, Config ) IO a) deriving (Functor, Applicative, Monad, MonadIO) +getCommonOptions :: CommandExec CommonOptions +getCommonOptions = CommandExec (asks fst) + getConfig :: CommandExec Config -getConfig = CommandExec ask +getConfig = CommandExec (asks snd) -- cgit v1.2.3