| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Arbiter.Core.Job.Types
Description
Job records, the enqueue setters, and the lifecycle hook types.
Synopsis
- type Job payload key q insertedAt adm = JobRecord payload key q insertedAt adm
- class HasKind payload where
- constructorKind :: (GKind (Rep a), Generic a) => a -> Text
- constructorKinds :: GKind (Rep a) => [Text]
- data PayloadKeys = PayloadKeys {}
- type JobRead payload = Job payload Int64 Text UTCTime PayloadKeys
- jobReadPairs :: ToJSON payload => JobRead payload -> [Pair]
- jobReadSeries :: ToJSON payload => JobRead payload -> Series
- data Stored payload
- storedBytes :: Stored payload -> ByteString
- toStored :: ToJSON payload => payload -> Stored payload
- decodeStored :: FromJSON payload => Stored payload -> Either Text payload
- type JobWrite payload = Job payload () () () ()
- type JobId = Int64
- type ClaimSeq = Int64
- primaryKey :: Job payload key q insertedAt adm -> key
- payload :: Job payload key q insertedAt adm -> payload
- queueName :: Job payload key q insertedAt adm -> q
- groupKey :: Job payload key q insertedAt adm -> Maybe Text
- insertedAt :: Job payload key q insertedAt adm -> insertedAt
- updatedAt :: Job payload Int64 q insertedAt adm -> Maybe UTCTime
- attempts :: Job payload Int64 q insertedAt adm -> Int32
- lastError :: Job payload Int64 q insertedAt adm -> Maybe Text
- priority :: Job payload key q insertedAt adm -> Int32
- lastAttemptedAt :: Job payload Int64 q insertedAt adm -> Maybe UTCTime
- notVisibleUntil :: Job payload key q insertedAt adm -> Maybe UTCTime
- dedupKey :: Job payload key q insertedAt adm -> Maybe DedupKey
- maxAttempts :: Job payload key q insertedAt adm -> Maybe Int32
- parentId :: Job payload Int64 q insertedAt adm -> Maybe Int64
- parentState :: Job payload Int64 q insertedAt adm -> Maybe Value
- traceContext :: Job payload key q insertedAt adm -> Maybe TraceContext
- suspended :: Job payload Int64 q insertedAt adm -> Bool
- claimedBy :: Job payload Int64 q insertedAt adm -> Maybe UUID
- claimSeq :: Job payload Int64 q insertedAt adm -> Int64
- archiveFor :: Job payload key q insertedAt adm -> Maybe Int32
- payloadKeys :: Job payload key q insertedAt adm -> adm
- defaultJob :: payload -> JobWrite payload
- defaultGroupedJob :: Text -> payload -> JobWrite payload
- setPayload :: payload' -> JobWrite payload -> JobWrite payload'
- setGroupKey :: Maybe Text -> JobWrite payload -> JobWrite payload
- setPriority :: Int32 -> JobWrite payload -> JobWrite payload
- setNotVisibleUntil :: Maybe UTCTime -> JobWrite payload -> JobWrite payload
- setDedupKey :: Maybe DedupKey -> JobWrite payload -> JobWrite payload
- setMaxAttempts :: Maybe Int32 -> JobWrite payload -> JobWrite payload
- setTraceContext :: Maybe TraceContext -> JobWrite payload -> JobWrite payload
- setArchiveFor :: Maybe Int32 -> JobWrite payload -> JobWrite payload
- mapPayload :: (payload -> payload') -> Job payload key q insertedAt adm -> Job payload' key q insertedAt adm
- defaultMaxAttempts :: Int32
- minMaxAttempts :: Int32
- dayRetention :: Int32
- isRollup :: Job p Int64 q t adm -> Bool
- data JobStatus
- jobStatusToText :: JobStatus -> Text
- jobStatusFromText :: Text -> Either Text JobStatus
- type JobPayload payload = (FromJSON payload, ToJSON payload, HasKind payload, HasRateLimit payload, HasConcurrency payload)
- type RegistryAdmissionPolicies (registry :: JobPayloadRegistry) = (RegistryConcurrencyPolicies registry, RegistryRateLimitPolicies registry)
- data DedupKey
- data TraceContext = TraceContext {
- traceparent :: Text
- tracestate :: Maybe Text
- toTraceContext :: Maybe Text -> Maybe Text -> Maybe TraceContext
- data ObservabilityHooks (m :: Type -> Type) payload = ObservabilityHooks {
- onJobClaimed :: JobPayload payload => JobRead payload -> ClaimTime -> m ()
- onJobSuccess :: JobPayload payload => JobRead payload -> StartTime -> EndTime -> m ()
- onJobFailure :: JobPayload payload => JobRead payload -> ErrorMsg -> StartTime -> EndTime -> m ()
- onJobRetry :: JobPayload payload => JobRead payload -> BackoffDelay -> m ()
- onJobFailedAndMovedToDLQ :: JobPayload payload => JobRead payload -> ErrorMsg -> m ()
- onJobCancelled :: JobPayload payload => JobRead payload -> ErrorMsg -> m ()
- onJobUnavailable :: JobPayload payload => JobRead payload -> ErrorMsg -> m ()
- onJobHeartbeat :: JobPayload payload => JobRead payload -> CurrentTime -> StartTime -> m ()
- defaultObservabilityHooks :: forall (m :: Type -> Type) payload. Applicative m => ObservabilityHooks m payload
- hoistObservabilityHooks :: (forall a. m a -> n a) -> ObservabilityHooks m payload -> ObservabilityHooks n payload
- andThen :: MonadUnliftIO m => m () -> m () -> m ()
- type ClaimTime = UTCTime
- type CurrentTime = UTCTime
- type StartTime = UTCTime
- type EndTime = UTCTime
- type ErrorMsg = Text
- type BackoffDelay = NominalDiffTime
- data JobRecord payload key q insertedAt adm
- data PayloadColumns = PayloadColumns {}
- dedupParts :: Maybe DedupKey -> (Maybe Text, Maybe Text)
Core job type
type Job payload key q insertedAt adm = JobRecord payload key q insertedAt admSource #
A job parametrized over payload, primary key, queue name, insertion timestamp, and the columns derived from the payload. The constructor is internal.
class HasKind payload whereSource #
A payload's per-job variant label. With no instance, the job is unlabelled. An empty
instance on a Generic payload labels it with the constructor name.
Minimal complete definition
Nothing
constructorKind :: (GKind (Rep a), Generic a) => a -> TextSource #
A value's constructor name, for a payload that wraps a sum. Requires Generic.
instance HasKind Envelope where kindOf = Just . constructorKind . envelopePayload kindsFor = constructorKinds @EmailPayload
constructorKinds :: GKind (Rep a) => [Text]Source #
Every constructor name of a type, in declaration order.
data PayloadKeysSource #
The labels and keys a stored job carries from its payload, one field each.
Constructors
| PayloadKeys | |
Fields
| |
Instances
type JobRead payload = Job payload Int64 Text UTCTime PayloadKeysSource #
A job read from the database.
jobReadPairs :: ToJSON payload => JobRead payload -> [Pair]Source #
A job's JSON fields as key-value pairs.
jobReadSeries :: ToJSON payload => JobRead payload -> SeriesSource #
A job's JSON fields as an encoding series.
A payload as the JSON bytes the database holds. The type it decodes to is a phantom.
storedBytes :: Stored payload -> ByteStringSource #
The JSON bytes of a stored payload.
decodeStored :: FromJSON payload => Stored payload -> Either Text payloadSource #
Decode a stored payload, or the reason the type rejects it.
type JobWrite payload = Job payload () () () ()Source #
A job ready to enqueue. Arbiter owns claim, retry, parent, rollup, and suspension state. Use the exported setters to configure enqueue fields.
primaryKey :: Job payload key q insertedAt adm -> keySource #
Database-assigned identifier for a stored job.
groupKey :: Job payload key q insertedAt adm -> Maybe TextSource #
Serial-processing group, or Nothing for an ungrouped job.
insertedAt :: Job payload key q insertedAt adm -> insertedAtSource #
Time at which the job was inserted.
updatedAt :: Job payload Int64 q insertedAt adm -> Maybe UTCTimeSource #
Time at which the job was last updated.
lastError :: Job payload Int64 q insertedAt adm -> Maybe TextSource #
Error message from the last failed attempt.
priority :: Job payload key q insertedAt adm -> Int32Source #
Claim priority. Lower numbers have higher priority. In a group, a retried job goes first.
lastAttemptedAt :: Job payload Int64 q insertedAt adm -> Maybe UTCTimeSource #
Time at which a worker last claimed the job.
notVisibleUntil :: Job payload key q insertedAt adm -> Maybe UTCTimeSource #
Earliest time at which the job can be claimed.
dedupKey :: Job payload key q insertedAt adm -> Maybe DedupKeySource #
Deduplication strategy and key.
maxAttempts :: Job payload key q insertedAt adm -> Maybe Int32Source #
Attempt limit before the job moves to the DLQ.
parentId :: Job payload Int64 q insertedAt adm -> Maybe Int64Source #
Identifier of this job's parent in a job tree.
parentState :: Job payload Int64 q insertedAt adm -> Maybe ValueSource #
Snapshot of accumulated child results for a rollup finalizer.
traceContext :: Job payload key q insertedAt adm -> Maybe TraceContextSource #
W3C trace context captured at enqueue.
suspended :: Job payload Int64 q insertedAt adm -> BoolSource #
Whether the job is suspended. It stays unclaimable until resumed.
claimedBy :: Job payload Int64 q insertedAt adm -> Maybe UUIDSource #
Holder of the outstanding claim. Nothing when no claim is outstanding.
archiveFor :: Job payload key q insertedAt adm -> Maybe Int32Source #
Completed-job archive retention in seconds.
payloadKeys :: Job payload key q insertedAt adm -> admSource #
The labels and keys stamped from the payload at enqueue.
defaultJob :: payload -> JobWrite payloadSource #
Ungrouped JobWrite with default values. For serial processing within a
group, use defaultGroupedJob.
defaultGroupedJob :: Text -> payload -> JobWrite payloadSource #
defaultJob with a group key. Jobs sharing a group key are processed serially.
setPayload :: payload' -> JobWrite payload -> JobWrite payload'Source #
Replace the payload.
setPriority :: Int32 -> JobWrite payload -> JobWrite payloadSource #
Set the claim priority. Lower numbers claim first. In a group, a retried job goes first.
setNotVisibleUntil :: Maybe UTCTime -> JobWrite payload -> JobWrite payloadSource #
Delay the job's first visibility.
setMaxAttempts :: Maybe Int32 -> JobWrite payload -> JobWrite payloadSource #
Set the attempt limit. Nothing takes defaultMaxAttempts. Values below
minMaxAttempts are raised to it.
setTraceContext :: Maybe TraceContext -> JobWrite payload -> JobWrite payloadSource #
Attach a trace context.
setArchiveFor :: Maybe Int32 -> JobWrite payload -> JobWrite payloadSource #
Set the archive retention, in seconds.
mapPayload :: (payload -> payload') -> Job payload key q insertedAt adm -> Job payload' key q insertedAt admSource #
Transform a job's payload without changing its stored metadata.
defaultMaxAttempts :: Int32Source #
Default attempt limit stamped onto jobs whose maxAttempts is unset.
minMaxAttempts :: Int32Source #
Lowest attempt limit a job is stamped with. Every job gets at least one attempt.
24h in seconds, a convenience value for setArchiveFor.
isRollup :: Job p Int64 q t adm -> BoolSource #
A rollup finalizer is any job whose parentState snapshot is present
(an empty object from its insert or spawn, the merged child results before a DLQ move).
Derived status
Effective job status. Arbiter derives status from the stored fields. The status SQL in Arbiter.Core.Sql.Jobs is its source of truth.
Constructors
| Ready | Visible, with attempts left. It can still wait behind its group head or a full concurrency or rate-limit key. |
| InFlight | Claimed by a worker, with the lease still running. |
| Backoff | Unclaimed with an attempt used, waiting out a delay. A nacked retry is here. |
| Scheduled | No attempt used, delayed to a future time. A nacked first attempt is here. |
| Suspended | Not claimable until resumed, such as a rollup finalizer with children. |
| Throttled | Held by a rate limit until tokens refill. |
| Cancelled | Force-cancel-flagged, waiting for teardown. |
| Exhausted | Visible but out of attempts, waiting for the reaper's DLQ sweep. |
Instances
| FromJSON JobStatus Source # | |||||
Defined in Arbiter.Core.Job.Status | |||||
| ToJSON JobStatus Source # | |||||
| Eq JobStatus Source # | |||||
| Bounded JobStatus Source # | |||||
| Enum JobStatus Source # | |||||
Defined in Arbiter.Core.Job.Status | |||||
| Generic JobStatus Source # | |||||
Defined in Arbiter.Core.Job.Status Associated Types
| |||||
| Show JobStatus Source # | |||||
| type Rep JobStatus Source # | |||||
Defined in Arbiter.Core.Job.Status type Rep JobStatus = D1 ('MetaData "JobStatus" "Arbiter.Core.Job.Status" "arbiter-core-0.1.0.0-inplace" 'False) (((C1 ('MetaCons "Ready" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "InFlight" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Backoff" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Scheduled" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "Suspended" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Throttled" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Cancelled" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Exhausted" 'PrefixI 'False) (U1 :: Type -> Type)))) | |||||
jobStatusToText :: JobStatus -> TextSource #
The wire name for a status.
jobStatusFromText :: Text -> Either Text JobStatusSource #
Strict inverse of jobStatusToText. Unknown values are rejected.
Type constraints
type JobPayload payload = (FromJSON payload, ToJSON payload, HasKind payload, HasRateLimit payload, HasConcurrency payload)Source #
The full payload contract. JSON round-trip for JSONB storage plus the kind, rate-limit and concurrency declarations. All three default to none.
type RegistryAdmissionPolicies (registry :: JobPayloadRegistry) = (RegistryConcurrencyPolicies registry, RegistryRateLimitPolicies registry)Source #
The constraint that lets the migration collect a registry's declared policies of both kinds.
Deduplication
Deduplication strategy, checked on INSERT via ON CONFLICT on the dedup key.
Constructors
| IgnoreDuplicate Text | Skip if the main queue table holds a job with this key ( |
| ReplaceDuplicate Text | Replace the main queue table's job with this key ( |
Instances
| FromJSON DedupKey Source # | |||||
Defined in Arbiter.Core.Job.Dedup | |||||
| ToJSON DedupKey Source # | |||||
| Eq DedupKey Source # | |||||
| Generic DedupKey Source # | |||||
Defined in Arbiter.Core.Job.Dedup Associated Types
| |||||
| Show DedupKey Source # | |||||
| type Rep DedupKey Source # | |||||
Defined in Arbiter.Core.Job.Dedup type Rep DedupKey = D1 ('MetaData "DedupKey" "Arbiter.Core.Job.Dedup" "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))) | |||||
Trace context
data TraceContextSource #
A job's W3C trace context.
Constructors
| TraceContext | |
Fields
| |
Instances
| Eq TraceContext Source # | |||||
Defined in Arbiter.Core.Job.TraceContext | |||||
| Generic TraceContext Source # | |||||
Defined in Arbiter.Core.Job.TraceContext Associated Types
| |||||
| Show TraceContext Source # | |||||
Defined in Arbiter.Core.Job.TraceContext Methods showsPrec :: Int -> TraceContext -> ShowS# show :: TraceContext -> String# showList :: [TraceContext] -> ShowS# | |||||
| type Rep TraceContext Source # | |||||
Defined in Arbiter.Core.Job.TraceContext type Rep TraceContext = D1 ('MetaData "TraceContext" "Arbiter.Core.Job.TraceContext" "arbiter-core-0.1.0.0-inplace" 'False) (C1 ('MetaCons "TraceContext" 'PrefixI 'True) (S1 ('MetaSel ('Just "traceparent") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "tracestate") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)))) | |||||
toTraceContext :: Maybe Text -> Maybe Text -> Maybe TraceContextSource #
A trace context from its two stored halves. An orphan tracestate is dropped.
Observability
data ObservabilityHooks (m :: Type -> Type) payloadSource #
Callbacks fired at each point of a job's lifecycle, for metrics, logging or tracing. The worker catches an exception thrown inside one and logs it at Warning.
Constructors
| ObservabilityHooks | |
Fields
| |
Instances
| MonadUnliftIO m => Monoid (ObservabilityHooks m payload) Source # | |
Defined in Arbiter.Core.Job.Types Methods mempty :: ObservabilityHooks m payload# mappend :: ObservabilityHooks m payload -> ObservabilityHooks m payload -> ObservabilityHooks m payload# mconcat :: [ObservabilityHooks m payload] -> ObservabilityHooks m payload# | |
| MonadUnliftIO m => Semigroup (ObservabilityHooks m payload) Source # | Run both hooks at each lifecycle point, left before right. The right one runs however the left ended. When both throw, the right's failure propagates. |
Defined in Arbiter.Core.Job.Types Methods (<>) :: ObservabilityHooks m payload -> ObservabilityHooks m payload -> ObservabilityHooks m payload# sconcat :: NonEmpty (ObservabilityHooks m payload) -> ObservabilityHooks m payload# stimes :: Integral b => b -> ObservabilityHooks m payload -> ObservabilityHooks m payload# | |
defaultObservabilityHooks :: forall (m :: Type -> Type) payload. Applicative m => ObservabilityHooks m payloadSource #
No-op hooks. Override fields to add observability:
myHooks = defaultObservabilityHooks
{ onJobSuccess = \job startTime endTime -> do
let duration = diffUTCTime endTime startTime
logInfo $ "Job " <> show (primaryKey job) <> " took " <> show duration
}
hoistObservabilityHooks :: (forall a. m a -> n a) -> ObservabilityHooks m payload -> ObservabilityHooks n payloadSource #
Hooks written in m, run in n through the given natural transformation.
It must be a monad morphism, such as lift.
andThen :: MonadUnliftIO m => m () -> m () -> m ()Source #
base's finally. The second action stays interruptible.
type CurrentTime = UTCTimeSource #
The worker's clock reading after the extend landed.
type EndTime = UTCTimeSource #
For a success, when the ack committed. For a failure, when the handler failed the job.
type BackoffDelay = NominalDiffTimeSource #
How long to wait before the next attempt.
Internal
Internal to the arbiter packages. Not covered by the PVP.
data JobRecord payload key q insertedAt admSource #
Internal representation shared by writable and stored jobs.
Instances
| FromJSON payload => FromJSON (JobRead payload) Source # | Decode the complete persisted representation of a job. |
Defined in Arbiter.Core.Job.Types | |
| ToJSON payload => ToJSON (JobRead payload) Source # | |
| (Eq key, Eq payload, Eq q, Eq insertedAt, Eq adm) => Eq (JobRecord payload key q insertedAt adm) Source # | |
| (Show key, Show payload, Show q, Show insertedAt, Show adm) => Show (JobRecord payload key q insertedAt adm) Source # | |
data PayloadColumnsSource #
The writable columns resolved from a payload at enqueue. The kind, key
and prefix columns round-trip via PayloadKeys. cost is write-only.
Constructors
| PayloadColumns | |
Fields
| |
Instances
| Eq PayloadColumns Source # | |||||
Defined in Arbiter.Core.Job.Types Methods (==) :: PayloadColumns -> PayloadColumns -> Bool# (/=) :: PayloadColumns -> PayloadColumns -> Bool# | |||||
| Generic PayloadColumns Source # | |||||
Defined in Arbiter.Core.Job.Types Associated Types
| |||||
| Show PayloadColumns Source # | |||||
Defined in Arbiter.Core.Job.Types Methods showsPrec :: Int -> PayloadColumns -> ShowS# show :: PayloadColumns -> String# showList :: [PayloadColumns] -> ShowS# | |||||
| type Rep PayloadColumns Source # | |||||
Defined in Arbiter.Core.Job.Types type Rep PayloadColumns = D1 ('MetaData "PayloadColumns" "Arbiter.Core.Job.Types" "arbiter-core-0.1.0.0-inplace" 'False) (C1 ('MetaCons "PayloadColumns" 'PrefixI 'True) ((S1 ('MetaSel ('Just "pcKind") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)) :*: (S1 ('MetaSel ('Just "pcRateLimitKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)) :*: S1 ('MetaSel ('Just "pcRateLimitPrefix") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)))) :*: (S1 ('MetaSel ('Just "pcRateLimitCost") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Double) :*: (S1 ('MetaSel ('Just "pcConcurrencyKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)) :*: S1 ('MetaSel ('Just "pcConcurrencyPrefix") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)))))) | |||||