summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarkfine <>2016-10-19 21:11:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2016-10-19 21:11:00 (GMT)
commit0134692f3c64bf757567ab413ef041c4d75890f9 (patch)
tree10abbb3b17364b2590c4c4d08dadcf8934ecf345
parent40be20635f9c7123dd348a1e21964c7e36317d3f (diff)
version 0.2.90.2.9
-rw-r--r--main/Act2.hs23
-rw-r--r--main/Options.hs8
-rw-r--r--wolf.cabal4
3 files changed, 31 insertions, 4 deletions
diff --git a/main/Act2.hs b/main/Act2.hs
index e866ce1..a32091f 100644
--- a/main/Act2.hs
+++ b/main/Act2.hs
@@ -6,6 +6,8 @@ module Act2
import BasicPrelude hiding ( ByteString, (</>), (<.>), hash, length, readFile, find )
import Codec.Compression.GZip
+import Control.Concurrent
+import Control.Concurrent.Async
import Control.Monad.Trans.Resource
import Data.Aeson.Encode
import Data.ByteString ( length )
@@ -13,6 +15,7 @@ import qualified Data.ByteString.Lazy as BL
import Data.Text ( pack, strip )
import Data.Text.Lazy ( toStrict )
import Data.Text.Lazy.Builder hiding ( fromText )
+import Data.Time
import Data.Yaml hiding ( Parser )
import Filesystem.Path ( (<.>), dropExtension )
import Network.AWS.Data.Crypto
@@ -25,13 +28,15 @@ data Args = Args
{ aConfig :: FilePath
, aQueue :: Queue
, aCommandLine :: Text
+ , aTimeout :: Int
} deriving ( Eq, Read, Show )
args :: Parser Args
args = Args <$>
configFile <*>
(pack <$> queue) <*>
- (pack <$> commandLine)
+ (pack <$> commandLine) <*>
+ timeout
parser :: ParserInfo Args
parser =
@@ -105,12 +110,24 @@ exec cmdline uid metadata blobs =
cd dir
maybe (return ()) (uncurry $ run_ . fromText) $ uncons $ words cmdline
+watchdog :: MVar UTCTime -> Int -> IO ()
+watchdog timestamp duration =
+ forever $ do
+ now <- getCurrentTime
+ now' <- readMVar timestamp
+ when (diffUTCTime now now' > fromIntegral duration) $
+ throwIO $ userError "watchdog expired"
+ threadDelay 1000000
+
call :: Args -> IO ()
call Args{..} = do
config <- decodeFile aConfig >>= maybeThrow (userError "Bad Config")
env <- flowEnv config
- forever $ runResourceT $ runFlowT env $
- act aQueue $ exec aCommandLine
+ timestamp <- newEmptyMVar
+ void $ concurrently (watchdog timestamp aTimeout) $ do
+ forever $ runResourceT $ runFlowT env $ do
+ liftIO $ getCurrentTime >>= putMVar timestamp
+ act aQueue $ exec aCommandLine
main :: IO ()
main = execParser parser >>= call
diff --git a/main/Options.hs b/main/Options.hs
index ad2463d..5dc9a33 100644
--- a/main/Options.hs
+++ b/main/Options.hs
@@ -7,6 +7,7 @@ module Options
, containerless
, gzip
, commandLine
+ , timeout
) where
import BasicPrelude
@@ -73,3 +74,10 @@ commandLine =
<> metavar "COMMAND"
<> help "Command to run"
+timeout :: Parser Int
+timeout =
+ option auto
+ $ long "timeout"
+ <> short 't'
+ <> metavar "TIMEOUT"
+ <> help "Timeout in seconds"
diff --git a/wolf.cabal b/wolf.cabal
index ff22967..2d7220e 100644
--- a/wolf.cabal
+++ b/wolf.cabal
@@ -1,5 +1,5 @@
name: wolf
-version: 0.2.8
+version: 0.2.9
synopsis: Amazon Simple Workflow Service Wrapper.
homepage: https://github.com/swift-nav/wolf
license: MIT
@@ -170,6 +170,7 @@ executable wolf-act2
ghc-options: -Wall -main-is Act2
build-depends: aeson
, amazonka-core
+ , async
, base
, basic-prelude
, bytestring
@@ -178,6 +179,7 @@ executable wolf-act2
, shelly
, system-filepath
, text
+ , time
, transformers
, wolf
, yaml