arbiter-core-0.1.0.0
arbiter-core
Safe HaskellNone
LanguageGHC2024

Arbiter.Core.Job.Types

Description

Job records, the enqueue setters, and the lifecycle hook types.

Synopsis

Core Job Type

Source #type Job payload key q insertedAt adm = JobRecord payload key q insertedAt adm

A job parametrized over payload, primary key, queue name, insertion timestamp, and the columns derived from the payload. The constructor is internal.

Source #class HasKind payload where

A payload's per-job variant label. Defaults to unlabelled.

Minimal complete definition

Nothing

Methods

Source #kindOf :: payload -> Maybe Text

The label stored for a job.

Source #default kindOf :: (GKindOf (Rep payload), Generic payload) => payload -> Maybe Text

Source #kindsFor :: [Text]

Every label kindOf can return. Empty when the set is not known.

Source #default kindsFor :: GKindsOf (Rep payload) => [Text]

Instances

Instances details
HasKind payload Source # 
Instance details

Defined in Arbiter.Core.Job.Kind

Methods

Source #kindOf :: payload -> Maybe Text

Source #kindsFor :: [Text]

Source #constructorKind :: (GKindOf (Rep a), Generic a) => a -> Text

The constructor name of a value, for a payload that wraps the sum it wants labelled. Needs Generic on the wrapped type.

instance HasKind Envelope where
  kindOf = Just . constructorKind . envelopePayload
  kindsFor = constructorKinds @EmailPayload

Source #constructorKinds :: GKindsOf (Rep a) => [Text]

Every constructor name of a type, in declaration order.

Source #data PayloadKeys

The labels and keys a stored job carries from its payload, one field each.

Constructors

PayloadKeys 

Fields

Instances

Instances details
Eq PayloadKeys Source # 
Instance details

Defined in Arbiter.Core.Job.Types

Generic PayloadKeys Source # 
Instance details

Defined in Arbiter.Core.Job.Types

Associated Types

type Rep PayloadKeys 
Instance details

Defined in Arbiter.Core.Job.Types

type Rep PayloadKeys = D1 ('MetaData "PayloadKeys" "Arbiter.Core.Job.Types" "arbiter-core-0.1.0.0-inplace" 'False) (C1 ('MetaCons "PayloadKeys" 'PrefixI 'True) (S1 ('MetaSel ('Just "jobKind") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)) :*: (S1 ('MetaSel ('Just "jobRateLimitKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe RateLimitKey)) :*: S1 ('MetaSel ('Just "jobConcurrencyKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe ConcurrencyKey)))))
Show PayloadKeys Source # 
Instance details

Defined in Arbiter.Core.Job.Types

FromJSON payload => FromJSON (JobRead payload) Source #

Decode the complete persisted representation of a job.

Instance details

Defined in Arbiter.Core.Job.Types

Methods

#parseJSON :: Value -> Parser (JobRead payload)

#parseJSONList :: Value -> Parser [JobRead payload]

#omittedField :: Maybe (JobRead payload)

type Rep PayloadKeys Source # 
Instance details

Defined in Arbiter.Core.Job.Types

type Rep PayloadKeys = D1 ('MetaData "PayloadKeys" "Arbiter.Core.Job.Types" "arbiter-core-0.1.0.0-inplace" 'False) (C1 ('MetaCons "PayloadKeys" 'PrefixI 'True) (S1 ('MetaSel ('Just "jobKind") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)) :*: (S1 ('MetaSel ('Just "jobRateLimitKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe RateLimitKey)) :*: S1 ('MetaSel ('Just "jobConcurrencyKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe ConcurrencyKey)))))

Source #data PayloadColumns

The writable columns resolved from a payload at enqueue. The kind, key and prefix columns round-trip via PayloadKeys. cost is write-only.

Instances

Instances details
Eq PayloadColumns Source # 
Instance details

Defined in Arbiter.Core.Job.Types

Generic PayloadColumns Source # 
Instance details

Defined in Arbiter.Core.Job.Types

Associated Types

type Rep PayloadColumns 
Instance details

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))))))
Show PayloadColumns Source # 
Instance details

Defined in Arbiter.Core.Job.Types

type Rep PayloadColumns Source # 
Instance details

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))))))

Source #type JobRead payload = Job payload Int64 Text UTCTime PayloadKeys

A job read from the database.

Source #type JobWrite payload = Job payload () () () ()

A job ready to enqueue. Arbiter owns claim, retry, parent, rollup, and suspension state. Use the exported setters to configure enqueue fields.

Source #primaryKey :: JobRecord payload key q insertedAt adm -> key

Database-assigned identifier for a stored job.

Source #payload :: JobRecord payload key q insertedAt adm -> payload

User-defined payload stored as JSONB.

Source #queueName :: JobRecord payload key q insertedAt adm -> q

Queue containing a stored job.

Source #groupKey :: JobRecord payload key q insertedAt adm -> Maybe Text

Serial-processing group, or Nothing for an ungrouped job.

Source #insertedAt :: JobRecord payload key q insertedAt adm -> insertedAt

Time at which the job was inserted.

Source #updatedAt :: JobRecord payload Int64 q insertedAt adm -> Maybe UTCTime

Time at which the job was last updated.

Source #attempts :: JobRecord payload Int64 q insertedAt adm -> Int32

Number of attempts made so far.

Source #lastError :: JobRecord payload Int64 q insertedAt adm -> Maybe Text

Error message from the last failed attempt.

Source #priority :: JobRecord payload key q insertedAt adm -> Int32

Claim priority. Lower numbers have higher priority.

Source #lastAttemptedAt :: JobRecord payload Int64 q insertedAt adm -> Maybe UTCTime

Time at which a worker last claimed the job.

Source #notVisibleUntil :: JobRecord payload key q insertedAt adm -> Maybe UTCTime

Earliest time at which the job can be claimed.

Source #dedupKey :: JobRecord payload key q insertedAt adm -> Maybe DedupKey

Deduplication strategy and key.

Source #maxAttempts :: JobRecord payload key q insertedAt adm -> Maybe Int32

Attempt limit before the job moves to the DLQ.

Source #parentId :: JobRecord payload Int64 q insertedAt adm -> Maybe Int64

Identifier of this job's parent in a job tree.

Source #parentState :: JobRecord payload Int64 q insertedAt adm -> Maybe Value

Snapshot of accumulated child results for a rollup finalizer.

Source #traceContext :: JobRecord payload key q insertedAt adm -> Maybe TraceContext

W3C trace context captured at enqueue.

Source #suspended :: JobRecord payload Int64 q insertedAt adm -> Bool

Whether the job is currently ineligible for claiming.

Source #claimedBy :: JobRecord payload Int64 q insertedAt adm -> Maybe UUID

Worker pool that most recently claimed the job.

Source #claimSeq :: JobRecord payload Int64 q insertedAt adm -> Int64

Monotonically increasing claim identifier.

Source #archiveFor :: JobRecord payload key q insertedAt adm -> Maybe Int32

Completed-job archive retention in seconds.

Source #payloadKeys :: JobRecord payload key q insertedAt adm -> adm

The labels and keys stamped from the payload at enqueue.

Source #defaultJob :: payload -> JobWrite payload

Ungrouped JobWrite with default values. For serial processing within a group, use defaultGroupedJob.

Source #defaultGroupedJob :: Text -> payload -> JobWrite payload

defaultJob with a group key. Jobs sharing a group key are processed serially.

Source #setPayload :: payload' -> JobWrite payload -> JobWrite payload'

Replace the payload.

Source #setGroupKey :: Maybe Text -> JobWrite payload -> JobWrite payload

Set the group key.

Source #setPriority :: Int32 -> JobWrite payload -> JobWrite payload

Set the claim priority. Lower numbers claim first.

Source #setNotVisibleUntil :: Maybe UTCTime -> JobWrite payload -> JobWrite payload

Delay the job's first visibility.

Source #setDedupKey :: Maybe DedupKey -> JobWrite payload -> JobWrite payload

Set the dedup key.

Source #setMaxAttempts :: Maybe Int32 -> JobWrite payload -> JobWrite payload

Override the queue's attempt limit.

Source #setTraceContext :: Maybe TraceContext -> JobWrite payload -> JobWrite payload

Attach a trace context.

Source #setArchiveFor :: Maybe Int32 -> JobWrite payload -> JobWrite payload

Set the archive retention, in seconds.

Source #mapPayload :: (payload -> payload') -> Job payload key q insertedAt adm -> Job payload' key q insertedAt adm

Transform a job's payload without changing its stored metadata.

Source #defaultMaxAttempts :: Int32

Default attempt limit stamped onto jobs whose maxAttempts is unset.

Source #dayRetention :: Int32

24h in seconds, a convenience value for archiveFor.

Source #isRollup :: Job p Int64 q t adm -> Bool

A rollup finalizer is any job whose parentState snapshot is present (an empty object on insert, the merged child results before a DLQ move).

Derived status

Source #data JobStatus

Effective job status. Arbiter derives status from the stored fields. The status SQL in Arbiter.Core.Sql.Jobs is its source of truth.

Instances

Instances details
FromJSON JobStatus Source # 
Instance details

Defined in Arbiter.Core.Job.Status

ToJSON JobStatus Source # 
Instance details

Defined in Arbiter.Core.Job.Status

Eq JobStatus Source # 
Instance details

Defined in Arbiter.Core.Job.Status

Bounded JobStatus Source # 
Instance details

Defined in Arbiter.Core.Job.Status

Enum JobStatus Source # 
Instance details

Defined in Arbiter.Core.Job.Status

Generic JobStatus Source # 
Instance details

Defined in Arbiter.Core.Job.Status

Associated Types

type Rep JobStatus 
Instance details

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))))
Show JobStatus Source # 
Instance details

Defined in Arbiter.Core.Job.Status

type Rep JobStatus Source # 
Instance details

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))))

Source #jobStatusToText :: JobStatus -> Text

The wire name for a status.

Source #jobStatusFromText :: Text -> Either Text JobStatus

Strict inverse of jobStatusToText. Unknown values are rejected.

Type Constraints

Source #type JobPayload payload = (FromJSON payload, ToJSON payload, HasKind payload, HasRateLimit payload, HasConcurrency payload)

The full payload contract. JSON round-trip for JSONB storage plus the rate-limit and concurrency declarations. Both default to unlimited.

Source #type RegistryAdmissionPolicies (registry :: JobPayloadRegistry) = (RegistryConcurrencyPolicies registry, RegistryRateLimitPolicies registry)

The registry declares both admission policy kinds.

Deduplication

Source #data DedupKey

Deduplication strategy, checked on INSERT via ON CONFLICT on the dedup key.

Constructors

IgnoreDuplicate Text

Skip if a job with this key exists (DO NOTHING).

ReplaceDuplicate Text

Replace the existing job with this key (DO UPDATE), unless it is actively claimed, force-cancel flagged, or has children.

Instances

Instances details
FromJSON DedupKey Source # 
Instance details

Defined in Arbiter.Core.Job.Dedup

ToJSON DedupKey Source # 
Instance details

Defined in Arbiter.Core.Job.Dedup

Eq DedupKey Source # 
Instance details

Defined in Arbiter.Core.Job.Dedup

Generic DedupKey Source # 
Instance details

Defined in Arbiter.Core.Job.Dedup

Associated Types

type Rep DedupKey 
Instance details

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)))
Show DedupKey Source # 
Instance details

Defined in Arbiter.Core.Job.Dedup

type Rep DedupKey Source # 
Instance details

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)))

Source #dedupParts :: Maybe DedupKey -> (Maybe Text, Maybe Text)

The dedup_key and dedup_strategy column values for a DedupKey.

Trace context

Source #data TraceContext

A job's W3C trace context.

Constructors

TraceContext 

Instances

Instances details
Eq TraceContext Source # 
Instance details

Defined in Arbiter.Core.Job.TraceContext

Generic TraceContext Source # 
Instance details

Defined in Arbiter.Core.Job.TraceContext

Associated Types

type Rep TraceContext 
Instance details

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))))
Show TraceContext Source # 
Instance details

Defined in Arbiter.Core.Job.TraceContext

type Rep TraceContext Source # 
Instance details

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))))

Source #toTraceContext :: Maybe Text -> Maybe Text -> Maybe TraceContext

A trace context from its two stored halves. An orphan tracestate is dropped.

Observability

Source #data ObservabilityHooks (m :: Type -> Type) payload

Callbacks fired at each point of a job's lifecycle, for metrics, logging or tracing. An exception thrown inside one is caught and dropped.

Constructors

ObservabilityHooks 

Fields

Instances

Instances details
MonadUnliftIO m => Monoid (ObservabilityHooks m payload) Source # 
Instance details

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.

Instance details

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

Source #defaultObservabilityHooks :: forall (m :: Type -> Type) payload. Applicative m => ObservabilityHooks m payload

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
  }

Source #andThen :: MonadUnliftIO m => m () -> m () -> m ()

base's finally. The second action stays interruptible.

Source #type JobId = Int64

A job's primary key.

Source #type ClaimSeq = Int64

The token identifying one claim of a job.

Source #type ClaimTime = UTCTime

When a claim was taken.

Source #type CurrentTime = UTCTime

The transaction's clock reading.

Source #type StartTime = UTCTime

When a handler began.

Source #type EndTime = UTCTime

When a handler finished.

Source #type ErrorMsg = Text

A failure message.

Source #type BackoffDelay = NominalDiffTime

How long to wait before the next attempt.