-- | Dead-letter queue types. Jobs land here after exhausting retries.
-- Recover with 'Arbiter.Core.HighLevel.retryFromDLQ' or delete with
-- 'Arbiter.Core.HighLevel.deleteDLQJob'.
module Arbiter.Core.Job.DLQ
  ( DLQJob (..)
  , JobSnapshot
  ) where

import Data.Int (Int64)
import Data.Text (Text)
import Data.Time (UTCTime)
import GHC.Generics (Generic)

import Arbiter.Core.Job.Types (Job)

-- | Full job state at the time of DLQ insertion.
type JobSnapshot payload = Job payload Int64 Text UTCTime

-- | A job in the dead-letter queue.
data DLQJob payload = DLQJob
  { forall payload. DLQJob payload -> Int64
dlqPrimaryKey :: Int64
  -- ^ DLQ table primary key (distinct from the original job ID in the snapshot)
  , forall payload. DLQJob payload -> UTCTime
failedAt :: UTCTime
  -- ^ When the job was moved to the DLQ
  , forall payload. DLQJob payload -> JobSnapshot payload
jobSnapshot :: JobSnapshot payload
  -- ^ Full job state at time of failure (payload, attempts, last_error, etc.).
  -- For DLQ'd rollup finalizers, 'parentState' on the snapshot carries the
  -- accumulated child results captured before the cascade delete.
  }
  deriving stock (DLQJob payload -> DLQJob payload -> Bool
(DLQJob payload -> DLQJob payload -> Bool)
-> (DLQJob payload -> DLQJob payload -> Bool)
-> Eq (DLQJob payload)
forall payload.
Eq payload =>
DLQJob payload -> DLQJob payload -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall payload.
Eq payload =>
DLQJob payload -> DLQJob payload -> Bool
== :: DLQJob payload -> DLQJob payload -> Bool
$c/= :: forall payload.
Eq payload =>
DLQJob payload -> DLQJob payload -> Bool
/= :: DLQJob payload -> DLQJob payload -> Bool
Eq, (forall x. DLQJob payload -> Rep (DLQJob payload) x)
-> (forall x. Rep (DLQJob payload) x -> DLQJob payload)
-> Generic (DLQJob payload)
forall x. Rep (DLQJob payload) x -> DLQJob payload
forall x. DLQJob payload -> Rep (DLQJob payload) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall payload x. Rep (DLQJob payload) x -> DLQJob payload
forall payload x. DLQJob payload -> Rep (DLQJob payload) x
$cfrom :: forall payload x. DLQJob payload -> Rep (DLQJob payload) x
from :: forall x. DLQJob payload -> Rep (DLQJob payload) x
$cto :: forall payload x. Rep (DLQJob payload) x -> DLQJob payload
to :: forall x. Rep (DLQJob payload) x -> DLQJob payload
Generic, Int -> DLQJob payload -> ShowS
[DLQJob payload] -> ShowS
DLQJob payload -> String
(Int -> DLQJob payload -> ShowS)
-> (DLQJob payload -> String)
-> ([DLQJob payload] -> ShowS)
-> Show (DLQJob payload)
forall payload. Show payload => Int -> DLQJob payload -> ShowS
forall payload. Show payload => [DLQJob payload] -> ShowS
forall payload. Show payload => DLQJob payload -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall payload. Show payload => Int -> DLQJob payload -> ShowS
showsPrec :: Int -> DLQJob payload -> ShowS
$cshow :: forall payload. Show payload => DLQJob payload -> String
show :: DLQJob payload -> String
$cshowList :: forall payload. Show payload => [DLQJob payload] -> ShowS
showList :: [DLQJob payload] -> ShowS
Show)