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

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

-- |
-- Module      : Amazonka.StepFunctions.SendTaskHeartbeat
-- 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)
--
-- Used by activity workers and task states using the
-- <https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html#connect-wait-token callback>
-- pattern to report to Step Functions that the task represented by the
-- specified @taskToken@ is still making progress. This action resets the
-- @Heartbeat@ clock. The @Heartbeat@ threshold is specified in the state
-- machine\'s Amazon States Language definition (@HeartbeatSeconds@). This
-- action does not in itself create an event in the execution history.
-- However, if the task times out, the execution history contains an
-- @ActivityTimedOut@ entry for activities, or a @TaskTimedOut@ entry for
-- for tasks using the
-- <https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html#connect-sync job run>
-- or
-- <https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html#connect-wait-token callback>
-- pattern.
--
-- The @Timeout@ of a task, defined in the state machine\'s Amazon States
-- Language definition, is its maximum allowed duration, regardless of the
-- number of SendTaskHeartbeat requests received. Use @HeartbeatSeconds@ to
-- configure the timeout interval for heartbeats.
module Amazonka.StepFunctions.SendTaskHeartbeat
  ( -- * Creating a Request
    SendTaskHeartbeat (..),
    newSendTaskHeartbeat,

    -- * Request Lenses
    sendTaskHeartbeat_taskToken,

    -- * Destructuring the Response
    SendTaskHeartbeatResponse (..),
    newSendTaskHeartbeatResponse,

    -- * Response Lenses
    sendTaskHeartbeatResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.StepFunctions.Types

-- | /See:/ 'newSendTaskHeartbeat' smart constructor.
data SendTaskHeartbeat = SendTaskHeartbeat'
  { -- | The token that represents this task. Task tokens are generated by Step
    -- Functions when tasks are assigned to a worker, or in the
    -- <https://docs.aws.amazon.com/step-functions/latest/dg/input-output-contextobject.html context object>
    -- when a workflow enters a task state. See
    -- GetActivityTaskOutput$taskToken.
    SendTaskHeartbeat -> Text
taskToken :: Prelude.Text
  }
  deriving (SendTaskHeartbeat -> SendTaskHeartbeat -> Bool
(SendTaskHeartbeat -> SendTaskHeartbeat -> Bool)
-> (SendTaskHeartbeat -> SendTaskHeartbeat -> Bool)
-> Eq SendTaskHeartbeat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SendTaskHeartbeat -> SendTaskHeartbeat -> Bool
$c/= :: SendTaskHeartbeat -> SendTaskHeartbeat -> Bool
== :: SendTaskHeartbeat -> SendTaskHeartbeat -> Bool
$c== :: SendTaskHeartbeat -> SendTaskHeartbeat -> Bool
Prelude.Eq, ReadPrec [SendTaskHeartbeat]
ReadPrec SendTaskHeartbeat
Int -> ReadS SendTaskHeartbeat
ReadS [SendTaskHeartbeat]
(Int -> ReadS SendTaskHeartbeat)
-> ReadS [SendTaskHeartbeat]
-> ReadPrec SendTaskHeartbeat
-> ReadPrec [SendTaskHeartbeat]
-> Read SendTaskHeartbeat
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SendTaskHeartbeat]
$creadListPrec :: ReadPrec [SendTaskHeartbeat]
readPrec :: ReadPrec SendTaskHeartbeat
$creadPrec :: ReadPrec SendTaskHeartbeat
readList :: ReadS [SendTaskHeartbeat]
$creadList :: ReadS [SendTaskHeartbeat]
readsPrec :: Int -> ReadS SendTaskHeartbeat
$creadsPrec :: Int -> ReadS SendTaskHeartbeat
Prelude.Read, Int -> SendTaskHeartbeat -> ShowS
[SendTaskHeartbeat] -> ShowS
SendTaskHeartbeat -> String
(Int -> SendTaskHeartbeat -> ShowS)
-> (SendTaskHeartbeat -> String)
-> ([SendTaskHeartbeat] -> ShowS)
-> Show SendTaskHeartbeat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SendTaskHeartbeat] -> ShowS
$cshowList :: [SendTaskHeartbeat] -> ShowS
show :: SendTaskHeartbeat -> String
$cshow :: SendTaskHeartbeat -> String
showsPrec :: Int -> SendTaskHeartbeat -> ShowS
$cshowsPrec :: Int -> SendTaskHeartbeat -> ShowS
Prelude.Show, (forall x. SendTaskHeartbeat -> Rep SendTaskHeartbeat x)
-> (forall x. Rep SendTaskHeartbeat x -> SendTaskHeartbeat)
-> Generic SendTaskHeartbeat
forall x. Rep SendTaskHeartbeat x -> SendTaskHeartbeat
forall x. SendTaskHeartbeat -> Rep SendTaskHeartbeat x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SendTaskHeartbeat x -> SendTaskHeartbeat
$cfrom :: forall x. SendTaskHeartbeat -> Rep SendTaskHeartbeat x
Prelude.Generic)

-- |
-- Create a value of 'SendTaskHeartbeat' 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:
--
-- 'taskToken', 'sendTaskHeartbeat_taskToken' - The token that represents this task. Task tokens are generated by Step
-- Functions when tasks are assigned to a worker, or in the
-- <https://docs.aws.amazon.com/step-functions/latest/dg/input-output-contextobject.html context object>
-- when a workflow enters a task state. See
-- GetActivityTaskOutput$taskToken.
newSendTaskHeartbeat ::
  -- | 'taskToken'
  Prelude.Text ->
  SendTaskHeartbeat
newSendTaskHeartbeat :: Text -> SendTaskHeartbeat
newSendTaskHeartbeat Text
pTaskToken_ =
  SendTaskHeartbeat' :: Text -> SendTaskHeartbeat
SendTaskHeartbeat' {$sel:taskToken:SendTaskHeartbeat' :: Text
taskToken = Text
pTaskToken_}

-- | The token that represents this task. Task tokens are generated by Step
-- Functions when tasks are assigned to a worker, or in the
-- <https://docs.aws.amazon.com/step-functions/latest/dg/input-output-contextobject.html context object>
-- when a workflow enters a task state. See
-- GetActivityTaskOutput$taskToken.
sendTaskHeartbeat_taskToken :: Lens.Lens' SendTaskHeartbeat Prelude.Text
sendTaskHeartbeat_taskToken :: (Text -> f Text) -> SendTaskHeartbeat -> f SendTaskHeartbeat
sendTaskHeartbeat_taskToken = (SendTaskHeartbeat -> Text)
-> (SendTaskHeartbeat -> Text -> SendTaskHeartbeat)
-> Lens SendTaskHeartbeat SendTaskHeartbeat Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendTaskHeartbeat' {Text
taskToken :: Text
$sel:taskToken:SendTaskHeartbeat' :: SendTaskHeartbeat -> Text
taskToken} -> Text
taskToken) (\s :: SendTaskHeartbeat
s@SendTaskHeartbeat' {} Text
a -> SendTaskHeartbeat
s {$sel:taskToken:SendTaskHeartbeat' :: Text
taskToken = Text
a} :: SendTaskHeartbeat)

instance Core.AWSRequest SendTaskHeartbeat where
  type
    AWSResponse SendTaskHeartbeat =
      SendTaskHeartbeatResponse
  request :: SendTaskHeartbeat -> Request SendTaskHeartbeat
request = Service -> SendTaskHeartbeat -> Request SendTaskHeartbeat
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy SendTaskHeartbeat
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse SendTaskHeartbeat)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse SendTaskHeartbeat))
-> Logger
-> Service
-> Proxy SendTaskHeartbeat
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse SendTaskHeartbeat)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> SendTaskHeartbeatResponse
SendTaskHeartbeatResponse'
            (Int -> SendTaskHeartbeatResponse)
-> Either String Int -> Either String SendTaskHeartbeatResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable SendTaskHeartbeat

instance Prelude.NFData SendTaskHeartbeat

instance Core.ToHeaders SendTaskHeartbeat where
  toHeaders :: SendTaskHeartbeat -> ResponseHeaders
toHeaders =
    ResponseHeaders -> SendTaskHeartbeat -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"AWSStepFunctions.SendTaskHeartbeat" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON SendTaskHeartbeat where
  toJSON :: SendTaskHeartbeat -> Value
toJSON SendTaskHeartbeat' {Text
taskToken :: Text
$sel:taskToken:SendTaskHeartbeat' :: SendTaskHeartbeat -> Text
..} =
    [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
"taskToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
taskToken)]
      )

instance Core.ToPath SendTaskHeartbeat where
  toPath :: SendTaskHeartbeat -> ByteString
toPath = ByteString -> SendTaskHeartbeat -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery SendTaskHeartbeat where
  toQuery :: SendTaskHeartbeat -> QueryString
toQuery = QueryString -> SendTaskHeartbeat -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newSendTaskHeartbeatResponse' smart constructor.
data SendTaskHeartbeatResponse = SendTaskHeartbeatResponse'
  { -- | The response's http status code.
    SendTaskHeartbeatResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (SendTaskHeartbeatResponse -> SendTaskHeartbeatResponse -> Bool
(SendTaskHeartbeatResponse -> SendTaskHeartbeatResponse -> Bool)
-> (SendTaskHeartbeatResponse -> SendTaskHeartbeatResponse -> Bool)
-> Eq SendTaskHeartbeatResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SendTaskHeartbeatResponse -> SendTaskHeartbeatResponse -> Bool
$c/= :: SendTaskHeartbeatResponse -> SendTaskHeartbeatResponse -> Bool
== :: SendTaskHeartbeatResponse -> SendTaskHeartbeatResponse -> Bool
$c== :: SendTaskHeartbeatResponse -> SendTaskHeartbeatResponse -> Bool
Prelude.Eq, ReadPrec [SendTaskHeartbeatResponse]
ReadPrec SendTaskHeartbeatResponse
Int -> ReadS SendTaskHeartbeatResponse
ReadS [SendTaskHeartbeatResponse]
(Int -> ReadS SendTaskHeartbeatResponse)
-> ReadS [SendTaskHeartbeatResponse]
-> ReadPrec SendTaskHeartbeatResponse
-> ReadPrec [SendTaskHeartbeatResponse]
-> Read SendTaskHeartbeatResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SendTaskHeartbeatResponse]
$creadListPrec :: ReadPrec [SendTaskHeartbeatResponse]
readPrec :: ReadPrec SendTaskHeartbeatResponse
$creadPrec :: ReadPrec SendTaskHeartbeatResponse
readList :: ReadS [SendTaskHeartbeatResponse]
$creadList :: ReadS [SendTaskHeartbeatResponse]
readsPrec :: Int -> ReadS SendTaskHeartbeatResponse
$creadsPrec :: Int -> ReadS SendTaskHeartbeatResponse
Prelude.Read, Int -> SendTaskHeartbeatResponse -> ShowS
[SendTaskHeartbeatResponse] -> ShowS
SendTaskHeartbeatResponse -> String
(Int -> SendTaskHeartbeatResponse -> ShowS)
-> (SendTaskHeartbeatResponse -> String)
-> ([SendTaskHeartbeatResponse] -> ShowS)
-> Show SendTaskHeartbeatResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SendTaskHeartbeatResponse] -> ShowS
$cshowList :: [SendTaskHeartbeatResponse] -> ShowS
show :: SendTaskHeartbeatResponse -> String
$cshow :: SendTaskHeartbeatResponse -> String
showsPrec :: Int -> SendTaskHeartbeatResponse -> ShowS
$cshowsPrec :: Int -> SendTaskHeartbeatResponse -> ShowS
Prelude.Show, (forall x.
 SendTaskHeartbeatResponse -> Rep SendTaskHeartbeatResponse x)
-> (forall x.
    Rep SendTaskHeartbeatResponse x -> SendTaskHeartbeatResponse)
-> Generic SendTaskHeartbeatResponse
forall x.
Rep SendTaskHeartbeatResponse x -> SendTaskHeartbeatResponse
forall x.
SendTaskHeartbeatResponse -> Rep SendTaskHeartbeatResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep SendTaskHeartbeatResponse x -> SendTaskHeartbeatResponse
$cfrom :: forall x.
SendTaskHeartbeatResponse -> Rep SendTaskHeartbeatResponse x
Prelude.Generic)

-- |
-- Create a value of 'SendTaskHeartbeatResponse' 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:
--
-- 'httpStatus', 'sendTaskHeartbeatResponse_httpStatus' - The response's http status code.
newSendTaskHeartbeatResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  SendTaskHeartbeatResponse
newSendTaskHeartbeatResponse :: Int -> SendTaskHeartbeatResponse
newSendTaskHeartbeatResponse Int
pHttpStatus_ =
  SendTaskHeartbeatResponse' :: Int -> SendTaskHeartbeatResponse
SendTaskHeartbeatResponse'
    { $sel:httpStatus:SendTaskHeartbeatResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

-- | The response's http status code.
sendTaskHeartbeatResponse_httpStatus :: Lens.Lens' SendTaskHeartbeatResponse Prelude.Int
sendTaskHeartbeatResponse_httpStatus :: (Int -> f Int)
-> SendTaskHeartbeatResponse -> f SendTaskHeartbeatResponse
sendTaskHeartbeatResponse_httpStatus = (SendTaskHeartbeatResponse -> Int)
-> (SendTaskHeartbeatResponse -> Int -> SendTaskHeartbeatResponse)
-> Lens SendTaskHeartbeatResponse SendTaskHeartbeatResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendTaskHeartbeatResponse' {Int
httpStatus :: Int
$sel:httpStatus:SendTaskHeartbeatResponse' :: SendTaskHeartbeatResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: SendTaskHeartbeatResponse
s@SendTaskHeartbeatResponse' {} Int
a -> SendTaskHeartbeatResponse
s {$sel:httpStatus:SendTaskHeartbeatResponse' :: Int
httpStatus = Int
a} :: SendTaskHeartbeatResponse)

instance Prelude.NFData SendTaskHeartbeatResponse