{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.RobOMaker.Types.BatchPolicy
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.RobOMaker.Types.BatchPolicy where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Information about the batch policy.
--
-- /See:/ 'newBatchPolicy' smart constructor.
data BatchPolicy = BatchPolicy'
  { -- | The amount of time, in seconds, to wait for the batch to complete.
    --
    -- If a batch times out, and there are pending requests that were failing
    -- due to an internal failure (like @InternalServiceError@), they will be
    -- moved to the failed list and the batch status will be @Failed@. If the
    -- pending requests were failing for any other reason, the failed pending
    -- requests will be moved to the failed list and the batch status will be
    -- @TimedOut@.
    BatchPolicy -> Maybe Integer
timeoutInSeconds :: Prelude.Maybe Prelude.Integer,
    -- | The number of active simulation jobs create as part of the batch that
    -- can be in an active state at the same time.
    --
    -- Active states include: @Pending@,@Preparing@, @Running@, @Restarting@,
    -- @RunningFailed@ and @Terminating@. All other states are terminal states.
    BatchPolicy -> Maybe Int
maxConcurrency :: Prelude.Maybe Prelude.Int
  }
  deriving (BatchPolicy -> BatchPolicy -> Bool
(BatchPolicy -> BatchPolicy -> Bool)
-> (BatchPolicy -> BatchPolicy -> Bool) -> Eq BatchPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchPolicy -> BatchPolicy -> Bool
$c/= :: BatchPolicy -> BatchPolicy -> Bool
== :: BatchPolicy -> BatchPolicy -> Bool
$c== :: BatchPolicy -> BatchPolicy -> Bool
Prelude.Eq, ReadPrec [BatchPolicy]
ReadPrec BatchPolicy
Int -> ReadS BatchPolicy
ReadS [BatchPolicy]
(Int -> ReadS BatchPolicy)
-> ReadS [BatchPolicy]
-> ReadPrec BatchPolicy
-> ReadPrec [BatchPolicy]
-> Read BatchPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchPolicy]
$creadListPrec :: ReadPrec [BatchPolicy]
readPrec :: ReadPrec BatchPolicy
$creadPrec :: ReadPrec BatchPolicy
readList :: ReadS [BatchPolicy]
$creadList :: ReadS [BatchPolicy]
readsPrec :: Int -> ReadS BatchPolicy
$creadsPrec :: Int -> ReadS BatchPolicy
Prelude.Read, Int -> BatchPolicy -> ShowS
[BatchPolicy] -> ShowS
BatchPolicy -> String
(Int -> BatchPolicy -> ShowS)
-> (BatchPolicy -> String)
-> ([BatchPolicy] -> ShowS)
-> Show BatchPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchPolicy] -> ShowS
$cshowList :: [BatchPolicy] -> ShowS
show :: BatchPolicy -> String
$cshow :: BatchPolicy -> String
showsPrec :: Int -> BatchPolicy -> ShowS
$cshowsPrec :: Int -> BatchPolicy -> ShowS
Prelude.Show, (forall x. BatchPolicy -> Rep BatchPolicy x)
-> (forall x. Rep BatchPolicy x -> BatchPolicy)
-> Generic BatchPolicy
forall x. Rep BatchPolicy x -> BatchPolicy
forall x. BatchPolicy -> Rep BatchPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchPolicy x -> BatchPolicy
$cfrom :: forall x. BatchPolicy -> Rep BatchPolicy x
Prelude.Generic)

-- |
-- Create a value of 'BatchPolicy' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'timeoutInSeconds', 'batchPolicy_timeoutInSeconds' - The amount of time, in seconds, to wait for the batch to complete.
--
-- If a batch times out, and there are pending requests that were failing
-- due to an internal failure (like @InternalServiceError@), they will be
-- moved to the failed list and the batch status will be @Failed@. If the
-- pending requests were failing for any other reason, the failed pending
-- requests will be moved to the failed list and the batch status will be
-- @TimedOut@.
--
-- 'maxConcurrency', 'batchPolicy_maxConcurrency' - The number of active simulation jobs create as part of the batch that
-- can be in an active state at the same time.
--
-- Active states include: @Pending@,@Preparing@, @Running@, @Restarting@,
-- @RunningFailed@ and @Terminating@. All other states are terminal states.
newBatchPolicy ::
  BatchPolicy
newBatchPolicy :: BatchPolicy
newBatchPolicy =
  BatchPolicy' :: Maybe Integer -> Maybe Int -> BatchPolicy
BatchPolicy'
    { $sel:timeoutInSeconds:BatchPolicy' :: Maybe Integer
timeoutInSeconds = Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:maxConcurrency:BatchPolicy' :: Maybe Int
maxConcurrency = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | The amount of time, in seconds, to wait for the batch to complete.
--
-- If a batch times out, and there are pending requests that were failing
-- due to an internal failure (like @InternalServiceError@), they will be
-- moved to the failed list and the batch status will be @Failed@. If the
-- pending requests were failing for any other reason, the failed pending
-- requests will be moved to the failed list and the batch status will be
-- @TimedOut@.
batchPolicy_timeoutInSeconds :: Lens.Lens' BatchPolicy (Prelude.Maybe Prelude.Integer)
batchPolicy_timeoutInSeconds :: (Maybe Integer -> f (Maybe Integer))
-> BatchPolicy -> f BatchPolicy
batchPolicy_timeoutInSeconds = (BatchPolicy -> Maybe Integer)
-> (BatchPolicy -> Maybe Integer -> BatchPolicy)
-> Lens BatchPolicy BatchPolicy (Maybe Integer) (Maybe Integer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchPolicy' {Maybe Integer
timeoutInSeconds :: Maybe Integer
$sel:timeoutInSeconds:BatchPolicy' :: BatchPolicy -> Maybe Integer
timeoutInSeconds} -> Maybe Integer
timeoutInSeconds) (\s :: BatchPolicy
s@BatchPolicy' {} Maybe Integer
a -> BatchPolicy
s {$sel:timeoutInSeconds:BatchPolicy' :: Maybe Integer
timeoutInSeconds = Maybe Integer
a} :: BatchPolicy)

-- | The number of active simulation jobs create as part of the batch that
-- can be in an active state at the same time.
--
-- Active states include: @Pending@,@Preparing@, @Running@, @Restarting@,
-- @RunningFailed@ and @Terminating@. All other states are terminal states.
batchPolicy_maxConcurrency :: Lens.Lens' BatchPolicy (Prelude.Maybe Prelude.Int)
batchPolicy_maxConcurrency :: (Maybe Int -> f (Maybe Int)) -> BatchPolicy -> f BatchPolicy
batchPolicy_maxConcurrency = (BatchPolicy -> Maybe Int)
-> (BatchPolicy -> Maybe Int -> BatchPolicy)
-> Lens BatchPolicy BatchPolicy (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchPolicy' {Maybe Int
maxConcurrency :: Maybe Int
$sel:maxConcurrency:BatchPolicy' :: BatchPolicy -> Maybe Int
maxConcurrency} -> Maybe Int
maxConcurrency) (\s :: BatchPolicy
s@BatchPolicy' {} Maybe Int
a -> BatchPolicy
s {$sel:maxConcurrency:BatchPolicy' :: Maybe Int
maxConcurrency = Maybe Int
a} :: BatchPolicy)

instance Core.FromJSON BatchPolicy where
  parseJSON :: Value -> Parser BatchPolicy
parseJSON =
    String
-> (Object -> Parser BatchPolicy) -> Value -> Parser BatchPolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"BatchPolicy"
      ( \Object
x ->
          Maybe Integer -> Maybe Int -> BatchPolicy
BatchPolicy'
            (Maybe Integer -> Maybe Int -> BatchPolicy)
-> Parser (Maybe Integer) -> Parser (Maybe Int -> BatchPolicy)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"timeoutInSeconds")
            Parser (Maybe Int -> BatchPolicy)
-> Parser (Maybe Int) -> Parser BatchPolicy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"maxConcurrency")
      )

instance Prelude.Hashable BatchPolicy

instance Prelude.NFData BatchPolicy

instance Core.ToJSON BatchPolicy where
  toJSON :: BatchPolicy -> Value
toJSON BatchPolicy' {Maybe Int
Maybe Integer
maxConcurrency :: Maybe Int
timeoutInSeconds :: Maybe Integer
$sel:maxConcurrency:BatchPolicy' :: BatchPolicy -> Maybe Int
$sel:timeoutInSeconds:BatchPolicy' :: BatchPolicy -> Maybe Integer
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"timeoutInSeconds" Text -> Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Integer -> Pair) -> Maybe Integer -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Integer
timeoutInSeconds,
            (Text
"maxConcurrency" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
maxConcurrency
          ]
      )