{-# 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.DataPipeline.ReportTaskProgress
-- 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)
--
-- Task runners call @ReportTaskProgress@ when assigned a task to
-- acknowledge that it has the task. If the web service does not receive
-- this acknowledgement within 2 minutes, it assigns the task in a
-- subsequent PollForTask call. After this initial acknowledgement, the
-- task runner only needs to report progress every 15 minutes to maintain
-- its ownership of the task. You can change this reporting time from 15
-- minutes by specifying a @reportProgressTimeout@ field in your pipeline.
--
-- If a task runner does not report its status after 5 minutes, AWS Data
-- Pipeline assumes that the task runner is unable to process the task and
-- reassigns the task in a subsequent response to PollForTask. Task runners
-- should call @ReportTaskProgress@ every 60 seconds.
module Amazonka.DataPipeline.ReportTaskProgress
  ( -- * Creating a Request
    ReportTaskProgress (..),
    newReportTaskProgress,

    -- * Request Lenses
    reportTaskProgress_fields,
    reportTaskProgress_taskId,

    -- * Destructuring the Response
    ReportTaskProgressResponse (..),
    newReportTaskProgressResponse,

    -- * Response Lenses
    reportTaskProgressResponse_httpStatus,
    reportTaskProgressResponse_canceled,
  )
where

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

-- | Contains the parameters for ReportTaskProgress.
--
-- /See:/ 'newReportTaskProgress' smart constructor.
data ReportTaskProgress = ReportTaskProgress'
  { -- | Key-value pairs that define the properties of the
    -- ReportTaskProgressInput object.
    ReportTaskProgress -> Maybe [Field]
fields :: Prelude.Maybe [Field],
    -- | The ID of the task assigned to the task runner. This value is provided
    -- in the response for PollForTask.
    ReportTaskProgress -> Text
taskId :: Prelude.Text
  }
  deriving (ReportTaskProgress -> ReportTaskProgress -> Bool
(ReportTaskProgress -> ReportTaskProgress -> Bool)
-> (ReportTaskProgress -> ReportTaskProgress -> Bool)
-> Eq ReportTaskProgress
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReportTaskProgress -> ReportTaskProgress -> Bool
$c/= :: ReportTaskProgress -> ReportTaskProgress -> Bool
== :: ReportTaskProgress -> ReportTaskProgress -> Bool
$c== :: ReportTaskProgress -> ReportTaskProgress -> Bool
Prelude.Eq, ReadPrec [ReportTaskProgress]
ReadPrec ReportTaskProgress
Int -> ReadS ReportTaskProgress
ReadS [ReportTaskProgress]
(Int -> ReadS ReportTaskProgress)
-> ReadS [ReportTaskProgress]
-> ReadPrec ReportTaskProgress
-> ReadPrec [ReportTaskProgress]
-> Read ReportTaskProgress
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ReportTaskProgress]
$creadListPrec :: ReadPrec [ReportTaskProgress]
readPrec :: ReadPrec ReportTaskProgress
$creadPrec :: ReadPrec ReportTaskProgress
readList :: ReadS [ReportTaskProgress]
$creadList :: ReadS [ReportTaskProgress]
readsPrec :: Int -> ReadS ReportTaskProgress
$creadsPrec :: Int -> ReadS ReportTaskProgress
Prelude.Read, Int -> ReportTaskProgress -> ShowS
[ReportTaskProgress] -> ShowS
ReportTaskProgress -> String
(Int -> ReportTaskProgress -> ShowS)
-> (ReportTaskProgress -> String)
-> ([ReportTaskProgress] -> ShowS)
-> Show ReportTaskProgress
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReportTaskProgress] -> ShowS
$cshowList :: [ReportTaskProgress] -> ShowS
show :: ReportTaskProgress -> String
$cshow :: ReportTaskProgress -> String
showsPrec :: Int -> ReportTaskProgress -> ShowS
$cshowsPrec :: Int -> ReportTaskProgress -> ShowS
Prelude.Show, (forall x. ReportTaskProgress -> Rep ReportTaskProgress x)
-> (forall x. Rep ReportTaskProgress x -> ReportTaskProgress)
-> Generic ReportTaskProgress
forall x. Rep ReportTaskProgress x -> ReportTaskProgress
forall x. ReportTaskProgress -> Rep ReportTaskProgress x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ReportTaskProgress x -> ReportTaskProgress
$cfrom :: forall x. ReportTaskProgress -> Rep ReportTaskProgress x
Prelude.Generic)

-- |
-- Create a value of 'ReportTaskProgress' 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:
--
-- 'fields', 'reportTaskProgress_fields' - Key-value pairs that define the properties of the
-- ReportTaskProgressInput object.
--
-- 'taskId', 'reportTaskProgress_taskId' - The ID of the task assigned to the task runner. This value is provided
-- in the response for PollForTask.
newReportTaskProgress ::
  -- | 'taskId'
  Prelude.Text ->
  ReportTaskProgress
newReportTaskProgress :: Text -> ReportTaskProgress
newReportTaskProgress Text
pTaskId_ =
  ReportTaskProgress' :: Maybe [Field] -> Text -> ReportTaskProgress
ReportTaskProgress'
    { $sel:fields:ReportTaskProgress' :: Maybe [Field]
fields = Maybe [Field]
forall a. Maybe a
Prelude.Nothing,
      $sel:taskId:ReportTaskProgress' :: Text
taskId = Text
pTaskId_
    }

-- | Key-value pairs that define the properties of the
-- ReportTaskProgressInput object.
reportTaskProgress_fields :: Lens.Lens' ReportTaskProgress (Prelude.Maybe [Field])
reportTaskProgress_fields :: (Maybe [Field] -> f (Maybe [Field]))
-> ReportTaskProgress -> f ReportTaskProgress
reportTaskProgress_fields = (ReportTaskProgress -> Maybe [Field])
-> (ReportTaskProgress -> Maybe [Field] -> ReportTaskProgress)
-> Lens
     ReportTaskProgress
     ReportTaskProgress
     (Maybe [Field])
     (Maybe [Field])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReportTaskProgress' {Maybe [Field]
fields :: Maybe [Field]
$sel:fields:ReportTaskProgress' :: ReportTaskProgress -> Maybe [Field]
fields} -> Maybe [Field]
fields) (\s :: ReportTaskProgress
s@ReportTaskProgress' {} Maybe [Field]
a -> ReportTaskProgress
s {$sel:fields:ReportTaskProgress' :: Maybe [Field]
fields = Maybe [Field]
a} :: ReportTaskProgress) ((Maybe [Field] -> f (Maybe [Field]))
 -> ReportTaskProgress -> f ReportTaskProgress)
-> ((Maybe [Field] -> f (Maybe [Field]))
    -> Maybe [Field] -> f (Maybe [Field]))
-> (Maybe [Field] -> f (Maybe [Field]))
-> ReportTaskProgress
-> f ReportTaskProgress
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Field] [Field] [Field] [Field]
-> Iso
     (Maybe [Field]) (Maybe [Field]) (Maybe [Field]) (Maybe [Field])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Field] [Field] [Field] [Field]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The ID of the task assigned to the task runner. This value is provided
-- in the response for PollForTask.
reportTaskProgress_taskId :: Lens.Lens' ReportTaskProgress Prelude.Text
reportTaskProgress_taskId :: (Text -> f Text) -> ReportTaskProgress -> f ReportTaskProgress
reportTaskProgress_taskId = (ReportTaskProgress -> Text)
-> (ReportTaskProgress -> Text -> ReportTaskProgress)
-> Lens ReportTaskProgress ReportTaskProgress Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReportTaskProgress' {Text
taskId :: Text
$sel:taskId:ReportTaskProgress' :: ReportTaskProgress -> Text
taskId} -> Text
taskId) (\s :: ReportTaskProgress
s@ReportTaskProgress' {} Text
a -> ReportTaskProgress
s {$sel:taskId:ReportTaskProgress' :: Text
taskId = Text
a} :: ReportTaskProgress)

instance Core.AWSRequest ReportTaskProgress where
  type
    AWSResponse ReportTaskProgress =
      ReportTaskProgressResponse
  request :: ReportTaskProgress -> Request ReportTaskProgress
request = Service -> ReportTaskProgress -> Request ReportTaskProgress
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy ReportTaskProgress
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ReportTaskProgress)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse ReportTaskProgress))
-> Logger
-> Service
-> Proxy ReportTaskProgress
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ReportTaskProgress)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int -> Bool -> ReportTaskProgressResponse
ReportTaskProgressResponse'
            (Int -> Bool -> ReportTaskProgressResponse)
-> Either String Int
-> Either String (Bool -> ReportTaskProgressResponse)
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))
            Either String (Bool -> ReportTaskProgressResponse)
-> Either String Bool -> Either String ReportTaskProgressResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String Bool
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"canceled")
      )

instance Prelude.Hashable ReportTaskProgress

instance Prelude.NFData ReportTaskProgress

instance Core.ToHeaders ReportTaskProgress where
  toHeaders :: ReportTaskProgress -> ResponseHeaders
toHeaders =
    ResponseHeaders -> ReportTaskProgress -> 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
"DataPipeline.ReportTaskProgress" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON ReportTaskProgress where
  toJSON :: ReportTaskProgress -> Value
toJSON ReportTaskProgress' {Maybe [Field]
Text
taskId :: Text
fields :: Maybe [Field]
$sel:taskId:ReportTaskProgress' :: ReportTaskProgress -> Text
$sel:fields:ReportTaskProgress' :: ReportTaskProgress -> Maybe [Field]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"fields" Text -> [Field] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Field] -> Pair) -> Maybe [Field] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Field]
fields,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"taskId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
taskId)
          ]
      )

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

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

-- | Contains the output of ReportTaskProgress.
--
-- /See:/ 'newReportTaskProgressResponse' smart constructor.
data ReportTaskProgressResponse = ReportTaskProgressResponse'
  { -- | The response's http status code.
    ReportTaskProgressResponse -> Int
httpStatus :: Prelude.Int,
    -- | If true, the calling task runner should cancel processing of the task.
    -- The task runner does not need to call SetTaskStatus for canceled tasks.
    ReportTaskProgressResponse -> Bool
canceled :: Prelude.Bool
  }
  deriving (ReportTaskProgressResponse -> ReportTaskProgressResponse -> Bool
(ReportTaskProgressResponse -> ReportTaskProgressResponse -> Bool)
-> (ReportTaskProgressResponse
    -> ReportTaskProgressResponse -> Bool)
-> Eq ReportTaskProgressResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReportTaskProgressResponse -> ReportTaskProgressResponse -> Bool
$c/= :: ReportTaskProgressResponse -> ReportTaskProgressResponse -> Bool
== :: ReportTaskProgressResponse -> ReportTaskProgressResponse -> Bool
$c== :: ReportTaskProgressResponse -> ReportTaskProgressResponse -> Bool
Prelude.Eq, ReadPrec [ReportTaskProgressResponse]
ReadPrec ReportTaskProgressResponse
Int -> ReadS ReportTaskProgressResponse
ReadS [ReportTaskProgressResponse]
(Int -> ReadS ReportTaskProgressResponse)
-> ReadS [ReportTaskProgressResponse]
-> ReadPrec ReportTaskProgressResponse
-> ReadPrec [ReportTaskProgressResponse]
-> Read ReportTaskProgressResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ReportTaskProgressResponse]
$creadListPrec :: ReadPrec [ReportTaskProgressResponse]
readPrec :: ReadPrec ReportTaskProgressResponse
$creadPrec :: ReadPrec ReportTaskProgressResponse
readList :: ReadS [ReportTaskProgressResponse]
$creadList :: ReadS [ReportTaskProgressResponse]
readsPrec :: Int -> ReadS ReportTaskProgressResponse
$creadsPrec :: Int -> ReadS ReportTaskProgressResponse
Prelude.Read, Int -> ReportTaskProgressResponse -> ShowS
[ReportTaskProgressResponse] -> ShowS
ReportTaskProgressResponse -> String
(Int -> ReportTaskProgressResponse -> ShowS)
-> (ReportTaskProgressResponse -> String)
-> ([ReportTaskProgressResponse] -> ShowS)
-> Show ReportTaskProgressResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReportTaskProgressResponse] -> ShowS
$cshowList :: [ReportTaskProgressResponse] -> ShowS
show :: ReportTaskProgressResponse -> String
$cshow :: ReportTaskProgressResponse -> String
showsPrec :: Int -> ReportTaskProgressResponse -> ShowS
$cshowsPrec :: Int -> ReportTaskProgressResponse -> ShowS
Prelude.Show, (forall x.
 ReportTaskProgressResponse -> Rep ReportTaskProgressResponse x)
-> (forall x.
    Rep ReportTaskProgressResponse x -> ReportTaskProgressResponse)
-> Generic ReportTaskProgressResponse
forall x.
Rep ReportTaskProgressResponse x -> ReportTaskProgressResponse
forall x.
ReportTaskProgressResponse -> Rep ReportTaskProgressResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ReportTaskProgressResponse x -> ReportTaskProgressResponse
$cfrom :: forall x.
ReportTaskProgressResponse -> Rep ReportTaskProgressResponse x
Prelude.Generic)

-- |
-- Create a value of 'ReportTaskProgressResponse' 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', 'reportTaskProgressResponse_httpStatus' - The response's http status code.
--
-- 'canceled', 'reportTaskProgressResponse_canceled' - If true, the calling task runner should cancel processing of the task.
-- The task runner does not need to call SetTaskStatus for canceled tasks.
newReportTaskProgressResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'canceled'
  Prelude.Bool ->
  ReportTaskProgressResponse
newReportTaskProgressResponse :: Int -> Bool -> ReportTaskProgressResponse
newReportTaskProgressResponse Int
pHttpStatus_ Bool
pCanceled_ =
  ReportTaskProgressResponse' :: Int -> Bool -> ReportTaskProgressResponse
ReportTaskProgressResponse'
    { $sel:httpStatus:ReportTaskProgressResponse' :: Int
httpStatus =
        Int
pHttpStatus_,
      $sel:canceled:ReportTaskProgressResponse' :: Bool
canceled = Bool
pCanceled_
    }

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

-- | If true, the calling task runner should cancel processing of the task.
-- The task runner does not need to call SetTaskStatus for canceled tasks.
reportTaskProgressResponse_canceled :: Lens.Lens' ReportTaskProgressResponse Prelude.Bool
reportTaskProgressResponse_canceled :: (Bool -> f Bool)
-> ReportTaskProgressResponse -> f ReportTaskProgressResponse
reportTaskProgressResponse_canceled = (ReportTaskProgressResponse -> Bool)
-> (ReportTaskProgressResponse
    -> Bool -> ReportTaskProgressResponse)
-> Lens
     ReportTaskProgressResponse ReportTaskProgressResponse Bool Bool
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReportTaskProgressResponse' {Bool
canceled :: Bool
$sel:canceled:ReportTaskProgressResponse' :: ReportTaskProgressResponse -> Bool
canceled} -> Bool
canceled) (\s :: ReportTaskProgressResponse
s@ReportTaskProgressResponse' {} Bool
a -> ReportTaskProgressResponse
s {$sel:canceled:ReportTaskProgressResponse' :: Bool
canceled = Bool
a} :: ReportTaskProgressResponse)

instance Prelude.NFData ReportTaskProgressResponse