{-# 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.Batch.Types.JobTimeout
-- 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.Batch.Types.JobTimeout where

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

-- | An object representing a job timeout configuration.
--
-- /See:/ 'newJobTimeout' smart constructor.
data JobTimeout = JobTimeout'
  { -- | The time duration in seconds (measured from the job attempt\'s
    -- @startedAt@ timestamp) after which Batch terminates your jobs if they
    -- have not finished. The minimum value for the timeout is 60 seconds.
    JobTimeout -> Maybe Int
attemptDurationSeconds :: Prelude.Maybe Prelude.Int
  }
  deriving (JobTimeout -> JobTimeout -> Bool
(JobTimeout -> JobTimeout -> Bool)
-> (JobTimeout -> JobTimeout -> Bool) -> Eq JobTimeout
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: JobTimeout -> JobTimeout -> Bool
$c/= :: JobTimeout -> JobTimeout -> Bool
== :: JobTimeout -> JobTimeout -> Bool
$c== :: JobTimeout -> JobTimeout -> Bool
Prelude.Eq, ReadPrec [JobTimeout]
ReadPrec JobTimeout
Int -> ReadS JobTimeout
ReadS [JobTimeout]
(Int -> ReadS JobTimeout)
-> ReadS [JobTimeout]
-> ReadPrec JobTimeout
-> ReadPrec [JobTimeout]
-> Read JobTimeout
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [JobTimeout]
$creadListPrec :: ReadPrec [JobTimeout]
readPrec :: ReadPrec JobTimeout
$creadPrec :: ReadPrec JobTimeout
readList :: ReadS [JobTimeout]
$creadList :: ReadS [JobTimeout]
readsPrec :: Int -> ReadS JobTimeout
$creadsPrec :: Int -> ReadS JobTimeout
Prelude.Read, Int -> JobTimeout -> ShowS
[JobTimeout] -> ShowS
JobTimeout -> String
(Int -> JobTimeout -> ShowS)
-> (JobTimeout -> String)
-> ([JobTimeout] -> ShowS)
-> Show JobTimeout
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [JobTimeout] -> ShowS
$cshowList :: [JobTimeout] -> ShowS
show :: JobTimeout -> String
$cshow :: JobTimeout -> String
showsPrec :: Int -> JobTimeout -> ShowS
$cshowsPrec :: Int -> JobTimeout -> ShowS
Prelude.Show, (forall x. JobTimeout -> Rep JobTimeout x)
-> (forall x. Rep JobTimeout x -> JobTimeout) -> Generic JobTimeout
forall x. Rep JobTimeout x -> JobTimeout
forall x. JobTimeout -> Rep JobTimeout x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep JobTimeout x -> JobTimeout
$cfrom :: forall x. JobTimeout -> Rep JobTimeout x
Prelude.Generic)

-- |
-- Create a value of 'JobTimeout' 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:
--
-- 'attemptDurationSeconds', 'jobTimeout_attemptDurationSeconds' - The time duration in seconds (measured from the job attempt\'s
-- @startedAt@ timestamp) after which Batch terminates your jobs if they
-- have not finished. The minimum value for the timeout is 60 seconds.
newJobTimeout ::
  JobTimeout
newJobTimeout :: JobTimeout
newJobTimeout =
  JobTimeout' :: Maybe Int -> JobTimeout
JobTimeout'
    { $sel:attemptDurationSeconds:JobTimeout' :: Maybe Int
attemptDurationSeconds =
        Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | The time duration in seconds (measured from the job attempt\'s
-- @startedAt@ timestamp) after which Batch terminates your jobs if they
-- have not finished. The minimum value for the timeout is 60 seconds.
jobTimeout_attemptDurationSeconds :: Lens.Lens' JobTimeout (Prelude.Maybe Prelude.Int)
jobTimeout_attemptDurationSeconds :: (Maybe Int -> f (Maybe Int)) -> JobTimeout -> f JobTimeout
jobTimeout_attemptDurationSeconds = (JobTimeout -> Maybe Int)
-> (JobTimeout -> Maybe Int -> JobTimeout)
-> Lens JobTimeout JobTimeout (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\JobTimeout' {Maybe Int
attemptDurationSeconds :: Maybe Int
$sel:attemptDurationSeconds:JobTimeout' :: JobTimeout -> Maybe Int
attemptDurationSeconds} -> Maybe Int
attemptDurationSeconds) (\s :: JobTimeout
s@JobTimeout' {} Maybe Int
a -> JobTimeout
s {$sel:attemptDurationSeconds:JobTimeout' :: Maybe Int
attemptDurationSeconds = Maybe Int
a} :: JobTimeout)

instance Core.FromJSON JobTimeout where
  parseJSON :: Value -> Parser JobTimeout
parseJSON =
    String
-> (Object -> Parser JobTimeout) -> Value -> Parser JobTimeout
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"JobTimeout"
      ( \Object
x ->
          Maybe Int -> JobTimeout
JobTimeout'
            (Maybe Int -> JobTimeout)
-> Parser (Maybe Int) -> Parser JobTimeout
forall (f :: * -> *) a b. Functor 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
"attemptDurationSeconds")
      )

instance Prelude.Hashable JobTimeout

instance Prelude.NFData JobTimeout

instance Core.ToJSON JobTimeout where
  toJSON :: JobTimeout -> Value
toJSON JobTimeout' {Maybe Int
attemptDurationSeconds :: Maybe Int
$sel:attemptDurationSeconds:JobTimeout' :: JobTimeout -> Maybe Int
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"attemptDurationSeconds" 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
attemptDurationSeconds
          ]
      )