summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarkfine <>2019-04-13 00:44:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2019-04-13 00:44:00 (GMT)
commit68474558d69862ca4ed7eda4554f34a4d86dffae (patch)
tree16df675e86cb7c9adf109ad00e7caa28e40a7a81
parent797d5dcdacc382c16754d110b450c50dc12ec947 (diff)
version 0.3.47HEAD0.3.47master
-rw-r--r--main/actor.hs9
-rw-r--r--src/Network/AWS/Wolf/Act.hs22
-rw-r--r--src/Network/AWS/Wolf/File.hs6
-rw-r--r--wolf.cabal2
4 files changed, 26 insertions, 13 deletions
diff --git a/main/actor.hs b/main/actor.hs
index 6708f4d..be2f80f 100644
--- a/main/actor.hs
+++ b/main/actor.hs
@@ -14,6 +14,8 @@ import Options.Generic
data Args = Args
{ config :: FilePath
-- ^ Configuration file.
+ , storeconf :: Bool
+ -- ^ Optional copy configuration file to output dorectory. (default: False)
, quiesce :: Maybe FilePath
-- ^ Optional quiesce file to stop actor.
, domain :: Maybe Text
@@ -22,14 +24,14 @@ data Args = Args
-- ^ Optional bucket to use.
, prefix :: Maybe Text
-- ^ Optional prefix to use.
- , queue :: Text
+ , queue :: [Text]
-- ^ Queue to listen to act on.
, num :: Maybe Int
-- ^ Number of actors to run concurrently.
, nocopy :: Bool
- -- ^ Copy working directory.
+ -- ^ Copy working directory. (default: False)
, local :: Bool
- -- ^ Run locally, not in a temp directory.
+ -- ^ Run locally, not in a temp directory. (default: False)
, include :: [FilePath]
-- ^ Optional artifacts to filter.
, command :: String
@@ -45,6 +47,7 @@ main = do
args <- getRecord "Actor"
actMain
(config args)
+ (storeconf args)
(quiesce args)
(domain args)
(bucket args)
diff --git a/src/Network/AWS/Wolf/Act.hs b/src/Network/AWS/Wolf/Act.hs
index 20b48fa..36a3362 100644
--- a/src/Network/AWS/Wolf/Act.hs
+++ b/src/Network/AWS/Wolf/Act.hs
@@ -75,8 +75,8 @@ check = maybe (pure False) (liftIO . doesFileExist)
-- | Actor logic - poll for work, download artifacts, run command, upload artifacts.
--
-act :: MonadConf c m => Text -> Bool -> Bool -> [FilePath] -> String -> m ()
-act queue nocopy local includes command =
+act :: MonadConf c m => Text -> Bool -> Bool -> [FilePath] -> String -> Bool -> m ()
+act queue nocopy local includes command storeconf =
preConfCtx [ "label" .= LabelAct ] $
runAmazonWorkCtx queue $ do
traceInfo "poll" mempty
@@ -96,6 +96,8 @@ act queue nocopy local includes command =
isd <- inputDirectory sd
osd <- outputDirectory sd
msd <- metaDirectory sd
+ conf <- view ccConf
+ when storeconf (writeYaml (osd </> "config.yml") conf)
writeJson (dd </> "control.json") (Control uid')
writeText (dd </> "input.json") input
writeText (msd </> (textToString queue <> "_input.json")) input
@@ -111,16 +113,18 @@ act queue nocopy local includes command =
statsIncrement "wolf.act.activity.count" [ "queue" =. queue, "status" =. status ]
statsHistogram "wolf.act.activity.elapsed" (realToFrac (diffUTCTime t3 t2) :: Double) [ "queue" =. queue ]
+
-- | Run actor from main with config file.
--
-actMain :: MonadControl m => FilePath -> Maybe FilePath -> Maybe Text -> Maybe Text -> Maybe Text -> Text -> Int -> Bool -> Bool -> [FilePath] -> String -> m ()
-actMain cf quiesce domain bucket prefix queue num nocopy local includes command =
+actMain :: MonadControl m => FilePath -> Bool -> Maybe FilePath -> Maybe Text -> Maybe Text -> Maybe Text -> [Text] -> Int -> Bool -> Bool -> [FilePath] -> String -> m ()
+actMain cf storeconf quiesce domain bucket prefix queues num nocopy local includes command =
runCtx $ runTop $ do
conf <- readYaml cf
let conf' = override cPrefix prefix $ override cBucket bucket $ override cDomain domain conf
runConfCtx conf' $
- runConcurrent $ replicate num $ forever $ do
- ok <- check quiesce
- when ok $
- liftIO exitSuccess
- act queue nocopy local includes command
+ runConcurrent $ replicate num $ forever $
+ forM_ (cycle queues) $ \queue -> do
+ ok <- check quiesce
+ when ok $
+ liftIO exitSuccess
+ act queue nocopy local includes command storeconf
diff --git a/src/Network/AWS/Wolf/File.hs b/src/Network/AWS/Wolf/File.hs
index 5b87ef2..257534c 100644
--- a/src/Network/AWS/Wolf/File.hs
+++ b/src/Network/AWS/Wolf/File.hs
@@ -12,6 +12,7 @@ module Network.AWS.Wolf.File
, writeText
, readText
, writeJson
+ , writeYaml
, readYaml
, withCurrentWorkDirectory
) where
@@ -88,6 +89,11 @@ writeJson file item =
liftIO $ withFile file WriteMode $ \h ->
BS.hPut h $ LBS.toStrict $ encode item
+-- | Encode from YAML and write file.
+--
+writeYaml :: (MonadIO m, ToJSON a) => FilePath -> a -> m ()
+writeYaml file item = liftIO $ encodeFile file item
+
-- | Read file and decode it from YAML.
--
readYaml :: (MonadIO m, FromJSON a) => FilePath -> m a
diff --git a/wolf.cabal b/wolf.cabal
index c709b78..d45fc93 100644
--- a/wolf.cabal
+++ b/wolf.cabal
@@ -1,6 +1,6 @@
cabal-version: >=1.22
name: wolf
-version: 0.3.46
+version: 0.3.47
license: MIT
license-file: LICENSE
copyright: Copyright (C) 2015-2016 Swift Navigation, Inc.