summaryrefslogtreecommitdiff
path: root/src/Network/AWS/Wolf/Count.hs
blob: ba3807480bbf0e74938aeac265b8fbf4b2124f42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{-# LANGUAGE FlexibleContexts  #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}

-- | SWF Counter logic.
--
module Network.AWS.Wolf.Count
  ( count
  , countMain
  ) where

import Network.AWS.Wolf.Ctx
import Network.AWS.Wolf.File
import Network.AWS.Wolf.Prelude
import Network.AWS.Wolf.SWF
import Network.AWS.Wolf.Types

-- | Count pending activities.
--
countActivity :: MonadConf c m => Task -> m ()
countActivity t = do
  traceInfo "count-act" [ "task" .= t ]
  let queue = t ^. tQueue
  runAmazonWorkCtx queue $ do
    c <- countActivities
    traceInfo "count-activities" [ "task" .= t, "count" .= c ]
    statsGauge "wolf.act.queue.depth" c [ "queue" =. queue ]

-- | Count open workflows.
--
countDecision :: MonadConf c m => Task -> m ()
countDecision t = do
  traceInfo "count-decision" [ "task" .= t ]
  let queue = t ^. tQueue
  runAmazonWorkCtx queue $ do
    c <- countDecisions
    traceInfo "count-decisions" [ "task" .= t, "count" .= c ]
    statsGauge "wolf.decide.queue.depth" c [ "queue" =. queue ]

-- | Counter logic - count all the queues.
--
count :: MonadConf c m => Plan -> m ()
count p =
  preConfCtx [ "label" .= LabelCount ] $
    runAmazonCtx $ do
      countDecision (p ^. pStart)
      mapM_ countActivity (p ^. pTasks)

-- | Run counter from main with config file.
--
countMain :: MonadControl m => FilePath -> FilePath -> m ()
countMain cf pf =
  runCtx $
    runStatsCtx $ do
      conf <- readYaml cf
      runConfCtx conf $ do
        plans <- readYaml pf
        mapM_ count (plans :: [Plan])