| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Arbiter.Core
Description
Re-exports commonly used Arbiter functionality.
Synopsis
- module Arbiter.Core.Job.DLQ
- constructorKind :: (GKind (Rep a), Generic a) => a -> Text
- constructorKinds :: GKind (Rep a) => [Text]
- jobStatusFromText :: Text -> Either Text JobStatus
- jobStatusToText :: JobStatus -> Text
- toTraceContext :: Maybe Text -> Maybe Text -> Maybe TraceContext
- andThen :: MonadUnliftIO m => m () -> m () -> m ()
- dayRetention :: Int32
- decodeStored :: FromJSON payload => Stored payload -> Either Text payload
- defaultGroupedJob :: Text -> payload -> JobWrite payload
- defaultJob :: payload -> JobWrite payload
- defaultMaxAttempts :: Int32
- defaultObservabilityHooks :: forall (m :: Type -> Type) payload. Applicative m => ObservabilityHooks m payload
- hoistObservabilityHooks :: (forall a. m a -> n a) -> ObservabilityHooks m payload -> ObservabilityHooks n payload
- isRollup :: Job p Int64 q t adm -> Bool
- jobReadPairs :: ToJSON payload => JobRead payload -> [Pair]
- jobReadSeries :: ToJSON payload => JobRead payload -> Series
- mapPayload :: (payload -> payload') -> Job payload key q insertedAt adm -> Job payload' key q insertedAt adm
- minMaxAttempts :: Int32
- setArchiveFor :: Maybe Int32 -> JobWrite payload -> JobWrite payload
- setDedupKey :: Maybe DedupKey -> JobWrite payload -> JobWrite payload
- setGroupKey :: Maybe Text -> JobWrite payload -> JobWrite payload
- setMaxAttempts :: Maybe Int32 -> JobWrite payload -> JobWrite payload
- setNotVisibleUntil :: Maybe UTCTime -> JobWrite payload -> JobWrite payload
- setPayload :: payload' -> JobWrite payload -> JobWrite payload'
- setPriority :: Int32 -> JobWrite payload -> JobWrite payload
- setTraceContext :: Maybe TraceContext -> JobWrite payload -> JobWrite payload
- toStored :: ToJSON payload => payload -> Stored payload
- archiveFor :: Job payload key q insertedAt adm -> Maybe Int32
- attempts :: Job payload Int64 q insertedAt adm -> Int32
- claimSeq :: Job payload Int64 q insertedAt adm -> Int64
- claimedBy :: Job payload Int64 q insertedAt adm -> Maybe UUID
- dedupKey :: Job payload key q insertedAt adm -> Maybe DedupKey
- groupKey :: Job payload key q insertedAt adm -> Maybe Text
- insertedAt :: Job payload key q insertedAt adm -> insertedAt
- lastAttemptedAt :: Job payload Int64 q insertedAt adm -> Maybe UTCTime
- lastError :: Job payload Int64 q insertedAt adm -> Maybe Text
- maxAttempts :: Job payload key q insertedAt adm -> Maybe Int32
- notVisibleUntil :: Job payload key q insertedAt adm -> Maybe UTCTime
- parentId :: Job payload Int64 q insertedAt adm -> Maybe Int64
- parentState :: Job payload Int64 q insertedAt adm -> Maybe Value
- payload :: Job payload key q insertedAt adm -> payload
- payloadKeys :: Job payload key q insertedAt adm -> adm
- primaryKey :: Job payload key q insertedAt adm -> key
- priority :: Job payload key q insertedAt adm -> Int32
- queueName :: Job payload key q insertedAt adm -> q
- storedBytes :: Stored payload -> ByteString
- suspended :: Job payload Int64 q insertedAt adm -> Bool
- traceContext :: Job payload key q insertedAt adm -> Maybe TraceContext
- updatedAt :: Job payload Int64 q insertedAt adm -> Maybe UTCTime
- data DedupKey
- class HasKind payload where
- data JobStatus
- data TraceContext = TraceContext {
- traceparent :: Text
- tracestate :: Maybe Text
- type BackoffDelay = NominalDiffTime
- type ClaimSeq = Int64
- type ClaimTime = UTCTime
- type CurrentTime = UTCTime
- type EndTime = UTCTime
- type ErrorMsg = Text
- type JobId = Int64
- type JobPayload payload = (FromJSON payload, ToJSON payload, HasKind payload, HasRateLimit payload, HasConcurrency payload)
- type JobRead payload = Job payload Int64 Text UTCTime PayloadKeys
- type JobWrite payload = Job payload () () () ()
- 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 ()
- data PayloadKeys = PayloadKeys {}
- type RegistryAdmissionPolicies (registry :: JobPayloadRegistry) = (RegistryConcurrencyPolicies registry, RegistryRateLimitPolicies registry)
- type StartTime = UTCTime
- type Job payload key q insertedAt adm = JobRecord payload key q insertedAt adm
- data Stored payload
- queryAny :: MonadArbiter m => Query Bool -> m Bool
- queryMaybe :: MonadArbiter m => Query a -> m (Maybe a)
- type family Handler (m :: Type -> Type) job result
- type HasRegistry (m :: Type -> Type) (registry :: JobPayloadRegistry) = (MonadArbiter m, RegistryOf m ~ registry)
- type JobHandler (m :: Type -> Type) payload result = Handler m (JobRead payload) result
- class MonadUnliftIO m => MonadArbiter (m :: Type -> Type) where
- type RegistryOf (m :: Type -> Type) :: JobPayloadRegistry
- type Handler (m :: Type -> Type) job result
- getSchema :: m SchemaName
- executeQuery :: Query a -> m [a]
- executeQueryPrepared :: Query a -> m [a]
- executeStatement :: Query a -> m Int64
- withDbTransaction :: m a -> m a
- runHandlerWithConnection :: JobHandler m payload (ResultOf m payload) -> JobRead payload -> m (ResultOf m payload)
- getListener :: m (Maybe Listener)
- type family RegistryOf (m :: Type -> Type) :: JobPayloadRegistry
- type ResultOf (m :: Type -> Type) payload = ResultFor payload (RegistryOf m)
- module Arbiter.Core.QueueRegistry
- module Arbiter.Core.HighLevel
- (<~~) :: JobWrite payload -> NonEmpty (JobWrite payload) -> JobTree payload
- leaf :: JobWrite payload -> JobTree payload
- rollup :: JobWrite payload -> NonEmpty (JobTree payload) -> JobTree payload
- data JobTree payload
- module Arbiter.Core.JobResult
- data ArchiveJob payload = ArchiveJob {
- archivePrimaryKey :: Int64
- completedAt :: UTCTime
- jobSnapshot :: JobSnapshot payload
- archivedResult :: Maybe Value
- type SchemaName = Text
- type TableName = Text
- orThrowInternal :: MonadIO m => (e -> Text) -> Either e a -> m a
- orThrowParsing :: MonadIO m => Either Text a -> m a
- throwBranchCancel :: MonadIO m => Text -> m a
- throwNack :: MonadIO m => m a
- throwNackAfter :: MonadIO m => NominalDiffTime -> m a
- throwPermanent :: MonadIO m => Text -> m a
- throwRetryable :: MonadIO m => Text -> m a
- throwRetryableAfter :: MonadIO m => NominalDiffTime -> Text -> m a
- throwTreeCancel :: MonadIO m => Text -> m a
- newtype BranchCancelException = BranchCancelException Text
- newtype InternalException = InternalException Text
- newtype JobDeadlineExceeded = JobDeadlineExceeded Text
- data JobException
- data JobForceCancelled = JobForceCancelled [Int64] [Int64]
- data JobGoneException = JobGoneException Text [Int64]
- newtype JobNackException = JobNackException (Maybe NominalDiffTime)
- newtype JobPermanentException = JobPermanentException Text
- data JobRetryableException = JobRetryableException Text (Maybe NominalDiffTime)
- data JobScopedFailure = JobScopedFailure JobException [Int64]
- newtype ParsingException = ParsingException Text
- newtype TreeCancelException = TreeCancelException Text
- effectiveExpression :: CronScheduleRow -> Text
- effectiveOverlap :: CronScheduleRow -> Text
- effectiveTimezone :: CronScheduleRow -> Maybe Text
- workerHealthFromText :: Text -> Either Text WorkerHealth
- workerHealthToText :: WorkerHealth -> Text
- module Arbiter.Core.PoolConfig
- data Listener
- data ListenConn = ListenConn {
- listenNotifies :: IO (Maybe Notification)
- listenSocket :: IO (Maybe Fd)
- listenConsumeInput :: IO Bool
- listenExec :: ByteString -> IO (Either Text ())
- listenEscapeIdentifier :: ByteString -> IO (Maybe ByteString)
- data HubLog = HubLog {
- hubRecovered :: Text -> IO ()
- hubWarn :: Text -> IO ()
- hubError :: Text -> IO ()
- hubRepeatInterval :: NominalDiffTime
- withChannels :: MonadUnliftIO m => Listener -> HubLog -> [(ByteString, Notification -> m ())] -> (STM Bool -> m a) -> m a
- newListener :: ((ListenConn -> IO ()) -> IO ()) -> IO Listener
Core types
module Arbiter.Core.Job.DLQ
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.
jobStatusFromText :: Text -> Either Text JobStatusSource #
Strict inverse of jobStatusToText. Unknown values are rejected.
jobStatusToText :: JobStatus -> TextSource #
The wire name for a status.
toTraceContext :: Maybe Text -> Maybe Text -> Maybe TraceContextSource #
A trace context from its two stored halves. An orphan tracestate is dropped.
andThen :: MonadUnliftIO m => m () -> m () -> m ()Source #
base's finally. The second action stays interruptible.
24h in seconds, a convenience value for setArchiveFor.
decodeStored :: FromJSON payload => Stored payload -> Either Text payloadSource #
Decode a stored payload, or the reason the type rejects it.
defaultGroupedJob :: Text -> payload -> JobWrite payloadSource #
defaultJob with a group key. Jobs sharing a group key are processed serially.
defaultJob :: payload -> JobWrite payloadSource #
Ungrouped JobWrite with default values. For serial processing within a
group, use defaultGroupedJob.
defaultMaxAttempts :: Int32Source #
Default attempt limit stamped onto jobs whose maxAttempts is unset.
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.
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).
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.
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.
minMaxAttempts :: Int32Source #
Lowest attempt limit a job is stamped with. Every job gets at least one attempt.
setArchiveFor :: Maybe Int32 -> JobWrite payload -> JobWrite payloadSource #
Set the archive retention, in seconds.
setMaxAttempts :: Maybe Int32 -> JobWrite payload -> JobWrite payloadSource #
Set the attempt limit. Nothing takes defaultMaxAttempts. Values below
minMaxAttempts are raised to it.
setNotVisibleUntil :: Maybe UTCTime -> JobWrite payload -> JobWrite payloadSource #
Delay the job's first visibility.
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.
setTraceContext :: Maybe TraceContext -> JobWrite payload -> JobWrite payloadSource #
Attach a trace context.
archiveFor :: Job payload key q insertedAt adm -> Maybe Int32Source #
Completed-job archive retention in seconds.
claimedBy :: Job payload Int64 q insertedAt adm -> Maybe UUIDSource #
Holder of the outstanding claim. Nothing when no claim is outstanding.
dedupKey :: Job payload key q insertedAt adm -> Maybe DedupKeySource #
Deduplication strategy and key.
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.
lastAttemptedAt :: Job payload Int64 q insertedAt adm -> Maybe UTCTimeSource #
Time at which a worker last claimed the job.
lastError :: Job payload Int64 q insertedAt adm -> Maybe TextSource #
Error message from the last failed attempt.
maxAttempts :: Job payload key q insertedAt adm -> Maybe Int32Source #
Attempt limit before the job moves to the DLQ.
notVisibleUntil :: Job payload key q insertedAt adm -> Maybe UTCTimeSource #
Earliest time at which the job can be claimed.
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.
payloadKeys :: Job payload key q insertedAt adm -> admSource #
The labels and keys stamped from the payload at enqueue.
primaryKey :: Job payload key q insertedAt adm -> keySource #
Database-assigned identifier for a stored job.
priority :: Job payload key q insertedAt adm -> Int32Source #
Claim priority. Lower numbers have higher priority. In a group, a retried job goes first.
storedBytes :: Stored payload -> ByteStringSource #
The JSON bytes of a stored payload.
suspended :: Job payload Int64 q insertedAt adm -> BoolSource #
Whether the job is suspended. It stays unclaimable until resumed.
traceContext :: Job payload key q insertedAt adm -> Maybe TraceContextSource #
W3C trace context captured at enqueue.
updatedAt :: Job payload Int64 q insertedAt adm -> Maybe UTCTimeSource #
Time at which the job was last updated.
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
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
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)))) | |||||
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)))) | |||||
type BackoffDelay = NominalDiffTimeSource #
How long to wait before the next attempt.
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 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 JobRead payload = Job payload Int64 Text UTCTime PayloadKeysSource #
A job read from the database.
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.
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# | |
data PayloadKeysSource #
The labels and keys a stored job carries from its payload, one field each.
Constructors
| PayloadKeys | |
Fields
| |
Instances
| Eq PayloadKeys Source # | |||||
Defined in Arbiter.Core.Job.Types | |||||
| Generic PayloadKeys Source # | |||||
Defined in Arbiter.Core.Job.Types Associated Types
| |||||
| Show PayloadKeys Source # | |||||
Defined in Arbiter.Core.Job.Types Methods showsPrec :: Int -> PayloadKeys -> ShowS# show :: PayloadKeys -> String# showList :: [PayloadKeys] -> ShowS# | |||||
| 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 # | |||||
| type Rep PayloadKeys Source # | |||||
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))))) | |||||
type RegistryAdmissionPolicies (registry :: JobPayloadRegistry) = (RegistryConcurrencyPolicies registry, RegistryRateLimitPolicies registry)Source #
The constraint that lets the migration collect a registry's declared policies of both kinds.
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.
A payload as the JSON bytes the database holds. The type it decodes to is a phantom.
queryAny :: MonadArbiter m => Query Bool -> m BoolSource #
Run a boolean Query. The result is true when a row is true.
queryMaybe :: MonadArbiter m => Query a -> m (Maybe a)Source #
Run a Query and keep its first row.
type family Handler (m :: Type -> Type) job resultSource #
Backend-specific handler shape (for example Connection -> job -> m result).
JobHandler instantiates it at one queue's job and result types.
type HasRegistry (m :: Type -> Type) (registry :: JobPayloadRegistry) = (MonadArbiter m, RegistryOf m ~ registry)Source #
MonadArbiter with the registry named, for signatures that mention it.
type JobHandler (m :: Type -> Type) payload result = Handler m (JobRead payload) resultSource #
A handler for payload's queue. result is what its registry entry declares.
class MonadUnliftIO m => MonadArbiter (m :: Type -> Type) whereSource #
Database abstraction for job queue operations. Each backend (postgresql-simple, hasql, Orville) provides an instance that maps queries to its native driver.
The instance also names the monad's schema and queue registry. The high-level API resolves table names and result types from them at compile time.
Minimal complete definition
getSchema, executeQuery, executeStatement, withDbTransaction, runHandlerWithConnection, getListener
Associated Types
type RegistryOf (m :: Type -> Type) :: JobPayloadRegistrySource #
This monad's registry. The default reports an instance that omits it.
type RegistryOf (m :: Type -> Type) = TypeError ((('Text "No registry declared for " ':<>: 'ShowType m) ':$$: 'Text "Its MonadArbiter instance is missing the RegistryOf definition.") ':$$: (('Text "Add to the instance: type RegistryOf " ':<>: 'ShowType m) ':<>: 'Text " = YourRegistry")) :: JobPayloadRegistry
type Handler (m :: Type -> Type) job resultSource #
Backend-specific handler shape (for example Connection -> job -> m result).
JobHandler instantiates it at one queue's job and result types.
Methods
getSchema :: m SchemaNameSource #
The schema name for this monad's arbiter tables.
executeQuery :: Query a -> m [a]Source #
Run a query and decode the result rows. The text, its parameters, and the
decoder travel together in the Query.
executeQueryPrepared :: Query a -> m [a]Source #
executeQuery for a hot statement whose text is stable across calls. A
backend may prepare it once per connection.
executeStatement :: Query a -> m Int64Source #
Run a statement, returning the number of affected rows. The Query
decoder is ignored.
withDbTransaction :: m a -> m aSource #
Run an action in a transaction. Nesting creates savepoints.
runHandlerWithConnection :: JobHandler m payload (ResultOf m payload) -> JobRead payload -> m (ResultOf m payload)Source #
Run a job handler in the backend's handler shape.
getListener :: m (Maybe Listener)Source #
The env's shared LISTEN/NOTIFY listener, or Nothing for poll-only.
type family RegistryOf (m :: Type -> Type) :: JobPayloadRegistrySource #
This monad's registry. The default reports an instance that omits it.
type ResultOf (m :: Type -> Type) payload = ResultFor payload (RegistryOf m)Source #
The result type declared by payload's registry entry. It is not injective.
A signature naming it needs another argument to determine payload.
module Arbiter.Core.QueueRegistry
High-level operations
The admin row records share field names with each other and with Job.
Unqualified use needs DuplicateRecordFields or OverloadedRecordDot.
module Arbiter.Core.HighLevel
Job tree DSL
(<~~) :: JobWrite payload -> NonEmpty (JobWrite payload) -> JobTree payload infixr 6Source #
Infix rollup for leaf-only children.
defaultJob reducer <~~ (defaultJob mapper1 :| [defaultJob mapper2])
rollup :: JobWrite payload -> NonEmpty (JobTree payload) -> JobTree payloadSource #
A finalizer running once no child of it is left in the main queue. Nested rollups do not merge on their own. An intermediate finalizer returns the merged value for results to travel upward.
rollup (defaultJob root) ( leaf (defaultJob leaf1) :| [leaf (defaultJob leaf2)] )
A tree of jobs. Leaves are single jobs. Finalizers are parents with children that run immediately while the parent waits for completion.
Job results
module Arbiter.Core.JobResult
Archived jobs
data ArchiveJob payloadSource #
A completed job in the archive.
Constructors
| ArchiveJob | |
Fields
| |
Instances
| FromJSON payload => FromJSON (ArchiveJob payload) Source # | |||||
Defined in Arbiter.Core.Job.Archive Methods parseJSON :: Value -> Parser (ArchiveJob payload)# parseJSONList :: Value -> Parser [ArchiveJob payload]# omittedField :: Maybe (ArchiveJob payload)# | |||||
| ToJSON payload => ToJSON (ArchiveJob payload) Source # | |||||
Defined in Arbiter.Core.Job.Archive Methods toJSON :: ArchiveJob payload -> Value# toEncoding :: ArchiveJob payload -> Encoding# toJSONList :: [ArchiveJob payload] -> Value# toEncodingList :: [ArchiveJob payload] -> Encoding# omitField :: ArchiveJob payload -> Bool# | |||||
| Eq payload => Eq (ArchiveJob payload) Source # | |||||
Defined in Arbiter.Core.Job.Archive Methods (==) :: ArchiveJob payload -> ArchiveJob payload -> Bool# (/=) :: ArchiveJob payload -> ArchiveJob payload -> Bool# | |||||
| Generic (ArchiveJob payload) Source # | |||||
Defined in Arbiter.Core.Job.Archive Associated Types
Methods from :: ArchiveJob payload -> Rep (ArchiveJob payload) x# to :: Rep (ArchiveJob payload) x -> ArchiveJob payload# | |||||
| Show payload => Show (ArchiveJob payload) Source # | |||||
Defined in Arbiter.Core.Job.Archive Methods showsPrec :: Int -> ArchiveJob payload -> ShowS# show :: ArchiveJob payload -> String# showList :: [ArchiveJob payload] -> ShowS# | |||||
| type Rep (ArchiveJob payload) Source # | |||||
Defined in Arbiter.Core.Job.Archive type Rep (ArchiveJob payload) = D1 ('MetaData "ArchiveJob" "Arbiter.Core.Job.Archive" "arbiter-core-0.1.0.0-inplace" 'False) (C1 ('MetaCons "ArchiveJob" 'PrefixI 'True) ((S1 ('MetaSel ('Just "archivePrimaryKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64) :*: S1 ('MetaSel ('Just "completedAt") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 UTCTime)) :*: (S1 ('MetaSel ('Just "jobSnapshot") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (JobSnapshot payload)) :*: S1 ('MetaSel ('Just "archivedResult") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Value))))) | |||||
Schema names
type SchemaName = TextSource #
PostgreSQL schema name, e.g. "arbiter".
Exceptions
orThrowInternal :: MonadIO m => (e -> Text) -> Either e a -> m aSource #
The Right value, or throwInternal on the rendered Left.
orThrowParsing :: MonadIO m => Either Text a -> m aSource #
The Right value, or throwParsing on the Left message.
throwBranchCancel :: MonadIO m => Text -> m aSource #
Cancel the parent and every descendant. A job with no parent cancels only itself and its descendants.
throwNackAfter :: MonadIO m => NominalDiffTime -> m aSource #
Return the job to the queue without consuming an attempt, visible again after a delay in seconds.
throwPermanent :: MonadIO m => Text -> m aSource #
Fail the job straight to the DLQ.
throwRetryable :: MonadIO m => Text -> m aSource #
Fail the job and let it retry.
throwRetryableAfter :: MonadIO m => NominalDiffTime -> Text -> m aSource #
Fail the job and retry it after a delay in seconds, in place of the pool's backoff. The failure uses an attempt.
throwTreeCancel :: MonadIO m => Text -> m aSource #
Cancel the whole job tree.
newtype BranchCancelExceptionSource #
Cancel the parent and every descendant. A job with no parent cancels only itself and its descendants. A grandparent above is resumed.
Constructors
| BranchCancelException Text |
Instances
| Eq BranchCancelException Source # | |||||
Defined in Arbiter.Core.Exceptions Methods (==) :: BranchCancelException -> BranchCancelException -> Bool# (/=) :: BranchCancelException -> BranchCancelException -> Bool# | |||||
| Exception BranchCancelException Source # | |||||
Defined in Arbiter.Core.Exceptions | |||||
| Generic BranchCancelException Source # | |||||
Defined in Arbiter.Core.Exceptions Associated Types
Methods from :: BranchCancelException -> Rep BranchCancelException x# | |||||
| Show BranchCancelException Source # | |||||
Defined in Arbiter.Core.Exceptions Methods showsPrec :: Int -> BranchCancelException -> ShowS# show :: BranchCancelException -> String# showList :: [BranchCancelException] -> ShowS# | |||||
| type Rep BranchCancelException Source # | |||||
Defined in Arbiter.Core.Exceptions type Rep BranchCancelException = D1 ('MetaData "BranchCancelException" "Arbiter.Core.Exceptions" "arbiter-core-0.1.0.0-inplace" 'True) (C1 ('MetaCons "BranchCancelException" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text))) | |||||
newtype InternalExceptionSource #
Generic engine-internal failure, such as a missing connection or bad parameters.
Constructors
| InternalException Text |
Instances
| Eq InternalException Source # | |||||
Defined in Arbiter.Core.Exceptions Methods (==) :: InternalException -> InternalException -> Bool# (/=) :: InternalException -> InternalException -> Bool# | |||||
| Exception InternalException Source # | |||||
Defined in Arbiter.Core.Exceptions | |||||
| Generic InternalException Source # | |||||
Defined in Arbiter.Core.Exceptions Associated Types
Methods from :: InternalException -> Rep InternalException x# to :: Rep InternalException x -> InternalException# | |||||
| Show InternalException Source # | |||||
Defined in Arbiter.Core.Exceptions Methods showsPrec :: Int -> InternalException -> ShowS# show :: InternalException -> String# showList :: [InternalException] -> ShowS# | |||||
| type Rep InternalException Source # | |||||
Defined in Arbiter.Core.Exceptions type Rep InternalException = D1 ('MetaData "InternalException" "Arbiter.Core.Exceptions" "arbiter-core-0.1.0.0-inplace" 'True) (C1 ('MetaCons "InternalException" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text))) | |||||
newtype JobDeadlineExceededSource #
A batch's claim hooks and handler ran past the pool's maximum job duration. Classified as a retryable failure.
Constructors
| JobDeadlineExceeded Text |
Instances
| Eq JobDeadlineExceeded Source # | |||||
Defined in Arbiter.Core.Exceptions Methods (==) :: JobDeadlineExceeded -> JobDeadlineExceeded -> Bool# (/=) :: JobDeadlineExceeded -> JobDeadlineExceeded -> Bool# | |||||
| Exception JobDeadlineExceeded Source # | |||||
Defined in Arbiter.Core.Exceptions | |||||
| Generic JobDeadlineExceeded Source # | |||||
Defined in Arbiter.Core.Exceptions Associated Types
Methods from :: JobDeadlineExceeded -> Rep JobDeadlineExceeded x# to :: Rep JobDeadlineExceeded x -> JobDeadlineExceeded# | |||||
| Show JobDeadlineExceeded Source # | |||||
Defined in Arbiter.Core.Exceptions Methods showsPrec :: Int -> JobDeadlineExceeded -> ShowS# show :: JobDeadlineExceeded -> String# showList :: [JobDeadlineExceeded] -> ShowS# | |||||
| type Rep JobDeadlineExceeded Source # | |||||
Defined in Arbiter.Core.Exceptions type Rep JobDeadlineExceeded = D1 ('MetaData "JobDeadlineExceeded" "Arbiter.Core.Exceptions" "arbiter-core-0.1.0.0-inplace" 'True) (C1 ('MetaCons "JobDeadlineExceeded" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text))) | |||||
data JobExceptionSource #
Decisions a handler can signal by throwing. The worker catches it and retries, dead-letters or cancels the job.
Constructors
| Retryable JobRetryableException | Retries the job after its delay, or with backoff. |
| Permanent JobPermanentException | Moves the job to the DLQ. |
| TreeCancel TreeCancelException | Deletes the entire job tree from root to leaves. |
| BranchCancel BranchCancelException | Cancels the parent and every descendant. A job with no parent cancels only itself and its descendants. |
Instances
| Exception JobException Source # | |
Defined in Arbiter.Core.Exceptions Methods toException :: JobException -> SomeException# fromException :: SomeException -> Maybe JobException# | |
| Show JobException Source # | |
Defined in Arbiter.Core.Exceptions Methods showsPrec :: Int -> JobException -> ShowS# show :: JobException -> String# showList :: [JobException] -> ShowS# | |
data JobForceCancelledSource #
Async exception for an operator force-cancel. Names the cancelled jobs, then the jobs the same check found reclaimed or gone.
Constructors
| JobForceCancelled [Int64] [Int64] |
Instances
| Exception JobForceCancelled Source # | |
Defined in Arbiter.Core.Exceptions | |
| Show JobForceCancelled Source # | |
Defined in Arbiter.Core.Exceptions Methods showsPrec :: Int -> JobForceCancelled -> ShowS# show :: JobForceCancelled -> String# showList :: [JobForceCancelled] -> ShowS# | |
data JobGoneExceptionSource #
Job was deleted or reclaimed between claim and ack. The worker recognizes this
signal and skips retry/DLQ. The message is the reason reported to
onJobUnavailable. The ids are the jobs that are gone.
Empty when the thrower did not name them.
Constructors
| JobGoneException Text [Int64] |
Instances
| Eq JobGoneException Source # | |||||
Defined in Arbiter.Core.Exceptions Methods (==) :: JobGoneException -> JobGoneException -> Bool# (/=) :: JobGoneException -> JobGoneException -> Bool# | |||||
| Exception JobGoneException Source # | |||||
Defined in Arbiter.Core.Exceptions | |||||
| Generic JobGoneException Source # | |||||
Defined in Arbiter.Core.Exceptions Associated Types
Methods from :: JobGoneException -> Rep JobGoneException x# to :: Rep JobGoneException x -> JobGoneException# | |||||
| Show JobGoneException Source # | |||||
Defined in Arbiter.Core.Exceptions Methods showsPrec :: Int -> JobGoneException -> ShowS# show :: JobGoneException -> String# showList :: [JobGoneException] -> ShowS# | |||||
| type Rep JobGoneException Source # | |||||
Defined in Arbiter.Core.Exceptions type Rep JobGoneException = D1 ('MetaData "JobGoneException" "Arbiter.Core.Exceptions" "arbiter-core-0.1.0.0-inplace" 'False) (C1 ('MetaCons "JobGoneException" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Int64]))) | |||||
newtype JobNackExceptionSource #
Reprocess the job later without recording a failure (a soft nack). The worker skips retry/DLQ, hands back the attempt the claim consumed, and leaves the job to become visible again after the delay in seconds, or when its lease lapses when there is none.
Constructors
| JobNackException (Maybe NominalDiffTime) |
Instances
| Eq JobNackException Source # | |||||
Defined in Arbiter.Core.Exceptions Methods (==) :: JobNackException -> JobNackException -> Bool# (/=) :: JobNackException -> JobNackException -> Bool# | |||||
| Exception JobNackException Source # | |||||
Defined in Arbiter.Core.Exceptions | |||||
| Generic JobNackException Source # | |||||
Defined in Arbiter.Core.Exceptions Associated Types
Methods from :: JobNackException -> Rep JobNackException x# to :: Rep JobNackException x -> JobNackException# | |||||
| Show JobNackException Source # | |||||
Defined in Arbiter.Core.Exceptions Methods showsPrec :: Int -> JobNackException -> ShowS# show :: JobNackException -> String# showList :: [JobNackException] -> ShowS# | |||||
| type Rep JobNackException Source # | |||||
Defined in Arbiter.Core.Exceptions type Rep JobNackException = D1 ('MetaData "JobNackException" "Arbiter.Core.Exceptions" "arbiter-core-0.1.0.0-inplace" 'True) (C1 ('MetaCons "JobNackException" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe NominalDiffTime)))) | |||||
newtype JobPermanentExceptionSource #
Permanent failure. The job goes straight to the DLQ.
Constructors
| JobPermanentException Text |
Instances
| Eq JobPermanentException Source # | |||||
Defined in Arbiter.Core.Exceptions Methods (==) :: JobPermanentException -> JobPermanentException -> Bool# (/=) :: JobPermanentException -> JobPermanentException -> Bool# | |||||
| Exception JobPermanentException Source # | |||||
Defined in Arbiter.Core.Exceptions | |||||
| Generic JobPermanentException Source # | |||||
Defined in Arbiter.Core.Exceptions Associated Types
Methods from :: JobPermanentException -> Rep JobPermanentException x# | |||||
| Show JobPermanentException Source # | |||||
Defined in Arbiter.Core.Exceptions Methods showsPrec :: Int -> JobPermanentException -> ShowS# show :: JobPermanentException -> String# showList :: [JobPermanentException] -> ShowS# | |||||
| type Rep JobPermanentException Source # | |||||
Defined in Arbiter.Core.Exceptions type Rep JobPermanentException = D1 ('MetaData "JobPermanentException" "Arbiter.Core.Exceptions" "arbiter-core-0.1.0.0-inplace" 'True) (C1 ('MetaCons "JobPermanentException" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text))) | |||||
data JobRetryableExceptionSource #
Transient failure. The job is retried after the delay in seconds, or with the pool's backoff when there is none.
Constructors
| JobRetryableException Text (Maybe NominalDiffTime) |
Instances
| Eq JobRetryableException Source # | |||||
Defined in Arbiter.Core.Exceptions Methods (==) :: JobRetryableException -> JobRetryableException -> Bool# (/=) :: JobRetryableException -> JobRetryableException -> Bool# | |||||
| Exception JobRetryableException Source # | |||||
Defined in Arbiter.Core.Exceptions | |||||
| Generic JobRetryableException Source # | |||||
Defined in Arbiter.Core.Exceptions Associated Types
Methods from :: JobRetryableException -> Rep JobRetryableException x# | |||||
| Show JobRetryableException Source # | |||||
Defined in Arbiter.Core.Exceptions Methods showsPrec :: Int -> JobRetryableException -> ShowS# show :: JobRetryableException -> String# showList :: [JobRetryableException] -> ShowS# | |||||
| type Rep JobRetryableException Source # | |||||
Defined in Arbiter.Core.Exceptions type Rep JobRetryableException = D1 ('MetaData "JobRetryableException" "Arbiter.Core.Exceptions" "arbiter-core-0.1.0.0-inplace" 'False) (C1 ('MetaCons "JobRetryableException" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe NominalDiffTime)))) | |||||
data JobScopedFailureSource #
A failure that settles the jobs it names and no others.
Constructors
| JobScopedFailure JobException [Int64] |
Instances
| Exception JobScopedFailure Source # | |
Defined in Arbiter.Core.Exceptions | |
| Show JobScopedFailure Source # | |
Defined in Arbiter.Core.Exceptions Methods showsPrec :: Int -> JobScopedFailure -> ShowS# show :: JobScopedFailure -> String# showList :: [JobScopedFailure] -> ShowS# | |
newtype ParsingExceptionSource #
Row decoding failure (engine-internal). Classified as a permanent failure by the worker.
Constructors
| ParsingException Text |
Instances
| Eq ParsingException Source # | |||||
Defined in Arbiter.Core.Exceptions Methods (==) :: ParsingException -> ParsingException -> Bool# (/=) :: ParsingException -> ParsingException -> Bool# | |||||
| Exception ParsingException Source # | |||||
Defined in Arbiter.Core.Exceptions | |||||
| Generic ParsingException Source # | |||||
Defined in Arbiter.Core.Exceptions Associated Types
Methods from :: ParsingException -> Rep ParsingException x# to :: Rep ParsingException x -> ParsingException# | |||||
| Show ParsingException Source # | |||||
Defined in Arbiter.Core.Exceptions Methods showsPrec :: Int -> ParsingException -> ShowS# show :: ParsingException -> String# showList :: [ParsingException] -> ShowS# | |||||
| type Rep ParsingException Source # | |||||
Defined in Arbiter.Core.Exceptions type Rep ParsingException = D1 ('MetaData "ParsingException" "Arbiter.Core.Exceptions" "arbiter-core-0.1.0.0-inplace" 'True) (C1 ('MetaCons "ParsingException" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text))) | |||||
newtype TreeCancelExceptionSource #
Cancel the whole job tree, root to leaves.
Constructors
| TreeCancelException Text |
Instances
| Eq TreeCancelException Source # | |||||
Defined in Arbiter.Core.Exceptions Methods (==) :: TreeCancelException -> TreeCancelException -> Bool# (/=) :: TreeCancelException -> TreeCancelException -> Bool# | |||||
| Exception TreeCancelException Source # | |||||
Defined in Arbiter.Core.Exceptions | |||||
| Generic TreeCancelException Source # | |||||
Defined in Arbiter.Core.Exceptions Associated Types
Methods from :: TreeCancelException -> Rep TreeCancelException x# to :: Rep TreeCancelException x -> TreeCancelException# | |||||
| Show TreeCancelException Source # | |||||
Defined in Arbiter.Core.Exceptions Methods showsPrec :: Int -> TreeCancelException -> ShowS# show :: TreeCancelException -> String# showList :: [TreeCancelException] -> ShowS# | |||||
| type Rep TreeCancelException Source # | |||||
Defined in Arbiter.Core.Exceptions type Rep TreeCancelException = D1 ('MetaData "TreeCancelException" "Arbiter.Core.Exceptions" "arbiter-core-0.1.0.0-inplace" 'True) (C1 ('MetaCons "TreeCancelException" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text))) | |||||
Cron schedule and worker health helpers
effectiveExpression :: CronScheduleRow -> TextSource #
The override expression if set, else the default.
effectiveOverlap :: CronScheduleRow -> TextSource #
The override overlap policy if set, else the default.
effectiveTimezone :: CronScheduleRow -> Maybe TextSource #
The override timezone if set, else the default. Nothing means UTC.
workerHealthFromText :: Text -> Either Text WorkerHealthSource #
Decode the health SQL token into a WorkerHealth.
workerHealthToText :: WorkerHealth -> TextSource #
The health SQL token of a WorkerHealth.
Connection pool settings
module Arbiter.Core.PoolConfig
Listener
Notification collides with Database.PostgreSQL.Simple.Notification.
Import it from Arbiter.Core.Listen.
data ListenConnSource #
The connection operations the hub loop needs.
Constructors
| ListenConn | |
Fields
| |
Hub event reporting preferences for a registrant.
Constructors
| HubLog | |
Fields
| |
withChannels :: MonadUnliftIO m => Listener -> HubLog -> [(ByteString, Notification -> m ())] -> (STM Bool -> m a) -> m aSource #
newListener :: ((ListenConn -> IO ()) -> IO ()) -> IO ListenerSource #
A Listener with a fresh hub slot over a connection runner.