{-# 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.SageMaker.Types.RetryStrategy
-- 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.SageMaker.Types.RetryStrategy where

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

-- | The retry strategy to use when a training job fails due to an
-- @InternalServerError@. @RetryStrategy@ is specified as part of the
-- @CreateTrainingJob@ and @CreateHyperParameterTuningJob@ requests. You
-- can add the @StoppingCondition@ parameter to the request to limit the
-- training time for the complete job.
--
-- /See:/ 'newRetryStrategy' smart constructor.
data RetryStrategy = RetryStrategy'
  { -- | The number of times to retry the job. When the job is retried, it\'s
    -- @SecondaryStatus@ is changed to @STARTING@.
    RetryStrategy -> Natural
maximumRetryAttempts :: Prelude.Natural
  }
  deriving (RetryStrategy -> RetryStrategy -> Bool
(RetryStrategy -> RetryStrategy -> Bool)
-> (RetryStrategy -> RetryStrategy -> Bool) -> Eq RetryStrategy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RetryStrategy -> RetryStrategy -> Bool
$c/= :: RetryStrategy -> RetryStrategy -> Bool
== :: RetryStrategy -> RetryStrategy -> Bool
$c== :: RetryStrategy -> RetryStrategy -> Bool
Prelude.Eq, ReadPrec [RetryStrategy]
ReadPrec RetryStrategy
Int -> ReadS RetryStrategy
ReadS [RetryStrategy]
(Int -> ReadS RetryStrategy)
-> ReadS [RetryStrategy]
-> ReadPrec RetryStrategy
-> ReadPrec [RetryStrategy]
-> Read RetryStrategy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RetryStrategy]
$creadListPrec :: ReadPrec [RetryStrategy]
readPrec :: ReadPrec RetryStrategy
$creadPrec :: ReadPrec RetryStrategy
readList :: ReadS [RetryStrategy]
$creadList :: ReadS [RetryStrategy]
readsPrec :: Int -> ReadS RetryStrategy
$creadsPrec :: Int -> ReadS RetryStrategy
Prelude.Read, Int -> RetryStrategy -> ShowS
[RetryStrategy] -> ShowS
RetryStrategy -> String
(Int -> RetryStrategy -> ShowS)
-> (RetryStrategy -> String)
-> ([RetryStrategy] -> ShowS)
-> Show RetryStrategy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RetryStrategy] -> ShowS
$cshowList :: [RetryStrategy] -> ShowS
show :: RetryStrategy -> String
$cshow :: RetryStrategy -> String
showsPrec :: Int -> RetryStrategy -> ShowS
$cshowsPrec :: Int -> RetryStrategy -> ShowS
Prelude.Show, (forall x. RetryStrategy -> Rep RetryStrategy x)
-> (forall x. Rep RetryStrategy x -> RetryStrategy)
-> Generic RetryStrategy
forall x. Rep RetryStrategy x -> RetryStrategy
forall x. RetryStrategy -> Rep RetryStrategy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RetryStrategy x -> RetryStrategy
$cfrom :: forall x. RetryStrategy -> Rep RetryStrategy x
Prelude.Generic)

-- |
-- Create a value of 'RetryStrategy' 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:
--
-- 'maximumRetryAttempts', 'retryStrategy_maximumRetryAttempts' - The number of times to retry the job. When the job is retried, it\'s
-- @SecondaryStatus@ is changed to @STARTING@.
newRetryStrategy ::
  -- | 'maximumRetryAttempts'
  Prelude.Natural ->
  RetryStrategy
newRetryStrategy :: Natural -> RetryStrategy
newRetryStrategy Natural
pMaximumRetryAttempts_ =
  RetryStrategy' :: Natural -> RetryStrategy
RetryStrategy'
    { $sel:maximumRetryAttempts:RetryStrategy' :: Natural
maximumRetryAttempts =
        Natural
pMaximumRetryAttempts_
    }

-- | The number of times to retry the job. When the job is retried, it\'s
-- @SecondaryStatus@ is changed to @STARTING@.
retryStrategy_maximumRetryAttempts :: Lens.Lens' RetryStrategy Prelude.Natural
retryStrategy_maximumRetryAttempts :: (Natural -> f Natural) -> RetryStrategy -> f RetryStrategy
retryStrategy_maximumRetryAttempts = (RetryStrategy -> Natural)
-> (RetryStrategy -> Natural -> RetryStrategy)
-> Lens RetryStrategy RetryStrategy Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RetryStrategy' {Natural
maximumRetryAttempts :: Natural
$sel:maximumRetryAttempts:RetryStrategy' :: RetryStrategy -> Natural
maximumRetryAttempts} -> Natural
maximumRetryAttempts) (\s :: RetryStrategy
s@RetryStrategy' {} Natural
a -> RetryStrategy
s {$sel:maximumRetryAttempts:RetryStrategy' :: Natural
maximumRetryAttempts = Natural
a} :: RetryStrategy)

instance Core.FromJSON RetryStrategy where
  parseJSON :: Value -> Parser RetryStrategy
parseJSON =
    String
-> (Object -> Parser RetryStrategy)
-> Value
-> Parser RetryStrategy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RetryStrategy"
      ( \Object
x ->
          Natural -> RetryStrategy
RetryStrategy'
            (Natural -> RetryStrategy)
-> Parser Natural -> Parser RetryStrategy
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"MaximumRetryAttempts")
      )

instance Prelude.Hashable RetryStrategy

instance Prelude.NFData RetryStrategy

instance Core.ToJSON RetryStrategy where
  toJSON :: RetryStrategy -> Value
toJSON RetryStrategy' {Natural
maximumRetryAttempts :: Natural
$sel:maximumRetryAttempts:RetryStrategy' :: RetryStrategy -> Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"MaximumRetryAttempts"
                  Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
maximumRetryAttempts
              )
          ]
      )