| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Arbiter.Core.Job.Types
Synopsis
- data Job payload key q insertedAt = Job {
- primaryKey :: key
- payload :: payload
- queueName :: q
- groupKey :: Maybe Text
- insertedAt :: insertedAt
- updatedAt :: Maybe UTCTime
- attempts :: Int32
- lastError :: Maybe Text
- priority :: Int32
- lastAttemptedAt :: Maybe UTCTime
- notVisibleUntil :: Maybe UTCTime
- dedupKey :: Maybe DedupKey
- maxAttempts :: Maybe Int32
- parentId :: Maybe Int64
- isRollup :: Bool
- suspended :: Bool
- type JobRead payload = Job payload Int64 Text UTCTime
- type JobWrite payload = Job payload () () ()
- defaultJob :: payload -> JobWrite payload
- defaultGroupedJob :: Text -> payload -> JobWrite payload
- type JobPayload payload = (FromJSON payload, ToJSON payload)
- data DedupKey
- data ObservabilityHooks (m :: Type -> Type) payload = ObservabilityHooks {
- onJobClaimed :: JobPayload payload => JobRead payload -> UTCTime -> m ()
- onJobSuccess :: JobPayload payload => JobRead payload -> UTCTime -> UTCTime -> m ()
- onJobFailure :: JobPayload payload => JobRead payload -> Text -> UTCTime -> UTCTime -> m ()
- onJobRetry :: JobPayload payload => JobRead payload -> NominalDiffTime -> m ()
- onJobFailedAndMovedToDLQ :: JobPayload payload => Text -> JobRead payload -> m ()
- onJobHeartbeat :: JobPayload payload => JobRead payload -> UTCTime -> UTCTime -> m ()
- defaultObservabilityHooks :: forall (m :: Type -> Type) payload. Applicative m => ObservabilityHooks m payload
Core Job Type
data Job payload key q insertedAt Source #
The core Job type, representing a unit of work in the queue.
Constructors
| Job | |
Fields
| |
Instances
type JobRead payload = Job payload Int64 Text UTCTime Source #
A type alias for a job that has been read from the database.
type JobWrite payload = Job payload () () () Source #
A type alias for a job that is ready to be written to the database. It does not yet have an ID or insertion timestamp.
defaultJob :: payload -> JobWrite payload Source #
Creates an ungrouped JobWrite with default values.
Jobs created with this function can be processed in parallel by multiple workers.
For serial processing within a group, use defaultGroupedJob.
defaultGroupedJob :: Text -> payload -> JobWrite payload Source #
Creates a grouped JobWrite with default values.
Jobs with the same group key are processed serially (head-of-line blocking), ensuring that only one job per group is processed at a time. Use for operations that must be ordered, like processing events for a specific user.
let job = defaultGroupedJob "user-123" (MyPayload data)
Type Constraints
type JobPayload payload = (FromJSON payload, ToJSON payload) Source #
Constraint for types that can be used as a job payload.
Payloads are serialized to and from JSON for storage in the database.
The table name is looked up from the registry via TableForPayload.
Deduplication
Defines the deduplication strategy for a job upon insertion.
Constructors
| IgnoreDuplicate Text | On conflict, keep the existing job. Corresponds to |
| ReplaceDuplicate Text | On conflict, replace the existing job with the new one. Corresponds to |
Instances
| FromJSON DedupKey Source # | |||||
Defined in Arbiter.Core.Job.Types | |||||
| ToJSON DedupKey Source # | |||||
Defined in Arbiter.Core.Job.Types Methods toEncoding :: DedupKey -> Encoding toJSONList :: [DedupKey] -> Value toEncodingList :: [DedupKey] -> Encoding | |||||
| Generic DedupKey Source # | |||||
Defined in Arbiter.Core.Job.Types Associated Types
| |||||
| Show DedupKey Source # | |||||
| Eq DedupKey Source # | |||||
| type Rep DedupKey Source # | |||||
Defined in Arbiter.Core.Job.Types type Rep DedupKey = D1 ('MetaData "DedupKey" "Arbiter.Core.Job.Types" "arbiter-core-0.1.0.0-inplace" 'False) (C1 ('MetaCons "IgnoreDuplicate" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)) :+: C1 ('MetaCons "ReplaceDuplicate" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text))) | |||||
Observability
data ObservabilityHooks (m :: Type -> Type) payload Source #
A set of callbacks invoked at key points in the job lifecycle.
Use these hooks to integrate with metrics, logging, or tracing systems. Hooks are exception-safe; any exception thrown within a hook is caught and ignored to prevent crashing the worker.
Constructors
| ObservabilityHooks | |
Fields
| |
defaultObservabilityHooks :: forall (m :: Type -> Type) payload. Applicative m => ObservabilityHooks m payload Source #
A default set of ObservabilityHooks that do nothing.
This can be used as a starting point for your own custom hooks.
myHooks = defaultObservabilityHooks
{ onJobSuccess = \job startTime endTime -> do
let duration = diffUTCTime endTime startTime
logInfo $ "Job " <> show (primaryKey job) <> " succeeded in " <> show duration
}