arbiter-core-0.1.0.0
arbiter-core
Safe HaskellNone
LanguageGHC2024

Arbiter.Core.Operations

Description

The job queue operations, over any MonadArbiter backend.

Synopsis

Job Insertion

Source #insertJob :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> JobWrite payload -> m (Maybe (JobRead payload))

Arguments

:: forall m payload. (JobPayload payload, MonadArbiter m) 
=> SchemaName

Schema name

-> TableName

Table name

-> JobWrite payload 
-> m (Maybe (JobRead payload)) 

Insert a job, returning it with its database-generated fields. Nothing when an IgnoreDuplicate key already exists, or a ReplaceDuplicate one names a job that is claimed, force-cancel flagged, or has children. Parent and rollup state come from insertJobTree.

Source #insertJobStamped :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> TraceStamp payload -> JobWrite payload -> m (Maybe (JobRead payload))

insertJob over a stamp the caller shares across its inserts.

Source #insertJobTreeNodeStamped :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> TraceStamp payload -> Maybe Int64 -> Maybe Value -> Bool -> JobWrite payload -> m (Maybe (JobRead payload))

Internal tree insertion path for engine-owned parent and suspension state.

Source #insertJobTreeLeavesStamped :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> TraceStamp payload -> Int64 -> [JobWrite payload] -> m [JobRead payload]

Batch-insert direct tree leaves under one parent.

Source #insertJobsBatch :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> [JobWrite payload] -> m [JobRead payload]

Arguments

:: forall m payload. (JobPayload payload, MonadArbiter m) 
=> SchemaName

Schema name

-> TableName

Table name

-> [JobWrite payload]

Jobs to insert

-> m [JobRead payload] 

insertJob over a batch in one round trip, returning the jobs inserted or replaced. Jobs sharing a dedup key within the batch collapse the way sequential insertJob calls would.

Source #insertJobsBatchStamped :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> TraceStamp payload -> [JobWrite payload] -> m [JobRead payload]

insertJobsBatch over a stamp the caller shares across its inserts.

Source #insertJobsBatch_ :: forall m payload. (JobPayload payload, MonadArbiter m) => Text -> Text -> [JobWrite payload] -> m Int64

insertJobsBatch discarding the rows, returning the count inserted.

Source #type TraceStamp payload = JobWrite payload -> JobWrite payload

What an insert path puts on its jobs, carrying the ambient trace context.

Source #traceStamp :: MonadIO m => m (TraceStamp payload)

The stamp for the context in scope. One read covers every job inserted under it.

Source #insertResult :: MonadArbiter m => SchemaName -> TableName -> Int64 -> Int64 -> Value -> m Int64

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> Int64

Parent job id

-> Int64

Child job id

-> Value

Encoded result value

-> m Int64 

Insert a child's result, keyed by (parent_id, child_id). Its foreign key cascades on the parent's ack.

Source #insertResultsBatch :: MonadArbiter m => SchemaName -> TableName -> [(Int64, Int64, Value)] -> m Int64

insertResult for several (parent id, child id, result) rows in one statement.

Source #getResultsByParent :: MonadArbiter m => SchemaName -> TableName -> Int64 -> m (Map Int64 Value)

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> Int64

Parent job id

-> m (Map Int64 Value) 

A parent's child results, keyed by child id.

Source #getDLQChildErrorsByParent :: MonadArbiter m => SchemaName -> TableName -> Int64 -> m (Map Int64 Text)

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> Int64

Parent job id

-> m (Map Int64 Text) 

A parent's DLQ'd children's last errors, keyed by child id.

Source #persistParentState :: MonadArbiter m => SchemaName -> TableName -> Int64 -> Value -> m Int64

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> Int64

Job id

-> Value

The pre-populated parent state to persist

-> m Int64 

Snapshot results into parent_state before DLQ move.

Source #claimNextVisibleJobs :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> Int -> NominalDiffTime -> m [JobRead payload]

Claim up to maxJobs visible jobs, one per group. Stamps anonymousClaimant.

Source #claimNextVisibleJobsAs :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> Int -> NominalDiffTime -> UUID -> m [JobRead payload]

claimNextVisibleJobs under a given worker id.

Source #claimNextVisibleJobsBatched :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> Int -> Int -> NominalDiffTime -> m [NonEmpty (JobRead payload)]

claimNextVisibleJobs claiming up to batchSize jobs from each of maxBatches groups. Stamps anonymousClaimant.

Source #data ClaimSql

A pool's claim statements, rendered once per capacity in [1 .. poolSize]. claimSqlFor falls back to a fresh render outside that range.

Constructors

ClaimSql 

Fields

Source #mkClaimSql :: JobPayload payload => proxy payload -> SchemaName -> TableName -> Int -> Int -> NominalDiffTime -> UUID -> ClaimSql

Assemble a pool's claim statements. Every input except the per-poll capacity is constant for the pool's lifetime.

Source #claimJobsCached :: forall m payload. (JobPayload payload, MonadArbiter m) => ClaimSql -> Int -> m [JobRead payload]

claimJobs over a prebuilt ClaimSql.

Source #claimJobsBatchedCached :: forall m payload. (JobPayload payload, MonadArbiter m) => ClaimSql -> Int -> m [NonEmpty (JobRead payload)]

claimJobsBatched over a prebuilt ClaimSql.

Source #addRateLimitTokens :: MonadArbiter m => SchemaName -> RateLimitKey -> Double -> m ()

Add tokens to a key's bucket, capped at its max. For operator top-ups and manually-refilled policies.

Source #pruneRateLimitBuckets :: MonadArbiter m => SchemaName -> NominalDiffTime -> m Int64

Delete full, idle rate-limit buckets. Returns the number pruned.

Source #resetRateLimitBuckets :: MonadArbiter m => SchemaName -> Text -> m Int64

Refill every bucket under a prefix to full. Returns the number refilled. Used to build a fixed window from a manual policy plus a cron.

Source #wakeThrottledJobs :: MonadArbiter m => SchemaName -> [TableName] -> Text -> m Int64

Make a prefix's throttled jobs claimable again across the given queue tables, in one statement. Returns the number woken.

Source #wakeThrottledJobsForKey :: MonadArbiter m => SchemaName -> [TableName] -> RateLimitKey -> m Int64

Wake one key's throttled jobs across the given tables, in one statement. Returns the count.

Source #listRateLimitPolicies :: MonadArbiter m => SchemaName -> [TableName] -> m [RateLimitPolicyView]

List every policy with its default/override params, bucket aggregates, and live throttled count across the given queue tables.

Source #getRateLimitPolicy :: MonadArbiter m => SchemaName -> [TableName] -> Text -> m (Maybe RateLimitPolicyView)

One prefix's policy view with bucket aggregates and live throttled count.

Source #rateLimitPolicyExists :: MonadArbiter m => SchemaName -> Text -> m Bool

Whether a rate-limit policy exists for a prefix.

Source #listRateLimitBuckets :: MonadArbiter m => SchemaName -> Text -> Int -> Int -> m [RateLimitBucketView]

List a prefix's buckets with effective max and fill fraction, paginated.

Source #listConcurrencyPolicies :: MonadArbiter m => SchemaName -> m [ConcurrencyPolicyView]

List every concurrency pool with its default/override limit and live key and in-flight aggregates.

Source #getConcurrencyPolicy :: MonadArbiter m => SchemaName -> Text -> m (Maybe ConcurrencyPolicyView)

One prefix's concurrency pool view with live aggregates.

Source #listConcurrencyKeys :: MonadArbiter m => SchemaName -> Text -> Int -> Int -> m [ConcurrencyKeyView]

List a prefix's keys with effective cap and fill fraction, paginated.

Source #updateRateLimitPolicyOverrides :: MonadArbiter m => SchemaName -> Text -> RateLimitPolicyUpdate -> m Int64

Set or clear a policy's override params. Returns rows affected (0 if absent).

Source #updateConcurrencyPolicyOverrides :: MonadArbiter m => SchemaName -> Text -> ConcurrencyPolicyUpdate -> m Int64

Apply a pool's override-limit patch (retunes every key under the prefix). Returns rows affected.

Source #pruneConcurrencyKeys :: MonadArbiter m => SchemaName -> [TableName] -> m Int64

Delete drained concurrency rows with no live job across the given tables. Returns the number pruned. A key whose advisory try-lock is contended is skipped until the next pass.

Source #reconcileConcurrencyCounts :: MonadArbiter m => SchemaName -> [TableName] -> m Int64

Lock the count rows, then recount those keys under the lock. A key seeded after the lock pass is left to its triggers.

Source #reconcileConcurrencyCountsIfStale :: MonadArbiter m => SchemaName -> [TableName] -> m Int64

Rebuild the counts when a crash truncated the UNLOGGED table. Returns the rows it recounted.

Source #reconcileAndPruneConcurrency :: MonadArbiter m => SchemaName -> [TableName] -> m Int64

Reconcile then prune, skipped when no concurrency key exists. Returns the rows recounted and pruned.

Source #ackJob :: MonadArbiter m => SchemaName -> TableName -> JobRead payload -> m Int64

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> JobRead payload 
-> m Int64 

Ack a completed job. Deletes a standalone one, suspends a parent whose children are still running, and wakes a parent whose last child finished. A child's ack takes the parent's advisory lock. Returns 1, or 0 for a job already gone.

Source #ackJobInner :: MonadArbiter m => SchemaName -> TableName -> JobRead payload -> m Int64

Inner ack logic, run inside the caller's transaction.

Source #ackJobsBatch :: MonadArbiter m => SchemaName -> TableName -> [JobRead payload] -> m [Int64]

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> [JobRead payload] 
-> m [Int64]

Ids acked (deleted or suspended). Reclaimed jobs are absent.

ackJob over a batch in one statement, locking the distinct parents to serialize with concurrent sibling acks.

Source #ackJobsBatchInner :: MonadArbiter m => SchemaName -> TableName -> [JobRead payload] -> m [Int64]

Inner batch ack, run inside the caller's transaction.

Source #lockJobParents :: MonadArbiter m => SchemaName -> TableName -> [Maybe Int64] -> m ()

Take the advisory lock of every distinct parent named, ascending, before any row lock the caller goes on to take.

Source #lockJobTrees :: MonadArbiter m => SchemaName -> TableName -> [Int64] -> m ()

Lock every job named and all of its descendants, in one descending pass.

Source #lockJobTreesFromRoot :: MonadArbiter m => SchemaName -> TableName -> [Int64] -> m ()

Apply lockJobTrees to the complete tree of each named job. Use these locks before tree cancellation.

Source #data TreeLocks

Whether the caller already took the parent and tree locks over its whole set.

Constructors

TakeLocks 
LocksHeld 

Instances

Instances details
Eq TreeLocks Source # 
Instance details

Defined in Arbiter.Core.Operations

Show TreeLocks Source # 
Instance details

Defined in Arbiter.Core.Operations

Source #archivesOnAck :: JobRead payload -> Bool

Whether acking this job tees it into the archive (positive archiveFor).

Source #setVisibilityTimeout :: MonadArbiter m => SchemaName -> TableName -> NominalDiffTime -> JobRead payload -> m Int64

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> NominalDiffTime

Timeout in seconds

-> JobRead payload 
-> m Int64

Rows updated. 0 for a row that is gone, reclaimed, or suspended.

Extend a job's visibility timeout.

Source #setVisibilityTimeoutBatch :: MonadArbiter m => SchemaName -> TableName -> NominalDiffTime -> [JobRead payload] -> m [VisibilityUpdateInfo]

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> NominalDiffTime

Timeout in seconds

-> [JobRead payload] 
-> m [VisibilityUpdateInfo]

One status record per job targeted.

setVisibilityTimeout over a batch, reporting each row through VisibilityUpdateInfo.

Source #data VisibilityUpdateInfo

What a batch visibility update found for one job.

Constructors

VisibilityUpdateInfo 

Fields

Instances

Instances details
Eq VisibilityUpdateInfo Source # 
Instance details

Defined in Arbiter.Core.Operations

Generic VisibilityUpdateInfo Source # 
Instance details

Defined in Arbiter.Core.Operations

Associated Types

type Rep VisibilityUpdateInfo 
Instance details

Defined in Arbiter.Core.Operations

type Rep VisibilityUpdateInfo = D1 ('MetaData "VisibilityUpdateInfo" "Arbiter.Core.Operations" "arbiter-core-0.1.0.0-inplace" 'False) (C1 ('MetaCons "VisibilityUpdateInfo" 'PrefixI 'True) ((S1 ('MetaSel ('Just "vuiJobId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 JobId) :*: (S1 ('MetaSel ('Just "vuiWasHeartbeated") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: S1 ('MetaSel ('Just "vuiCurrentDbClaimSeq") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe ClaimSeq)))) :*: (S1 ('MetaSel ('Just "vuiCancelRequested") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: (S1 ('MetaSel ('Just "vuiSuspended") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: S1 ('MetaSel ('Just "vuiClaimedBy") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe UUID))))))
Show VisibilityUpdateInfo Source # 
Instance details

Defined in Arbiter.Core.Operations

type Rep VisibilityUpdateInfo Source # 
Instance details

Defined in Arbiter.Core.Operations

type Rep VisibilityUpdateInfo = D1 ('MetaData "VisibilityUpdateInfo" "Arbiter.Core.Operations" "arbiter-core-0.1.0.0-inplace" 'False) (C1 ('MetaCons "VisibilityUpdateInfo" 'PrefixI 'True) ((S1 ('MetaSel ('Just "vuiJobId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 JobId) :*: (S1 ('MetaSel ('Just "vuiWasHeartbeated") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: S1 ('MetaSel ('Just "vuiCurrentDbClaimSeq") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe ClaimSeq)))) :*: (S1 ('MetaSel ('Just "vuiCancelRequested") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: (S1 ('MetaSel ('Just "vuiSuspended") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: S1 ('MetaSel ('Just "vuiClaimedBy") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe UUID))))))

Source #updateJobForRetry :: MonadArbiter m => SchemaName -> TableName -> NominalDiffTime -> Text -> JobRead payload -> m Int64

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> NominalDiffTime

Backoff timeout in seconds

-> Text

Error message

-> JobRead payload 
-> m Int64 

Park a failed job for its retry backoff, recording the error. Returns 0 for a job another worker holds.

Source #nackJob :: MonadArbiter m => SchemaName -> TableName -> JobRead payload -> m Int64

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> JobRead payload 
-> m Int64 

Soft-nack a job. Hands back the attempt the claim consumed and records no failure. Returns 0 for a job another worker holds.

Source #nackJobsBatch :: MonadArbiter m => SchemaName -> TableName -> [JobRead payload] -> m [Int64]

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> [JobRead payload] 
-> m [Int64] 

nackJob over a batch in one statement, returning the ids nacked. Jobs another worker holds are absent.

Source #moveToDLQ :: MonadArbiter m => TreeLocks -> SchemaName -> TableName -> Text -> JobRead payload -> m Int64

Arguments

:: MonadArbiter m 
=> TreeLocks 
-> SchemaName

Schema name

-> TableName

Table name

-> Text

Error message (the final error that caused the DLQ move)

-> JobRead payload 
-> m Int64 

Move a job to the DLQ, cascading a rollup parent's descendants with it and waking the parent of a child. Returns 0 for a job another worker holds.

Source #moveToDLQFields :: MonadArbiter m => TreeLocks -> DLQMove -> SchemaName -> TableName -> Text -> Int64 -> Int64 -> Maybe Int64 -> Bool -> m Int64

Arguments

:: MonadArbiter m 
=> TreeLocks 
-> DLQMove 
-> SchemaName 
-> TableName 
-> Text

Error message (the final error that caused the DLQ move)

-> Int64

Job id

-> Int64

Claim token (for the optimistic move check)

-> Maybe Int64

Parent id, if a child

-> Bool

Whether the job is a rollup finalizer

-> m Int64 

moveToDLQ driven by scalar fields, for callers without a typed JobRead.

Source #moveToDLQBatch :: MonadArbiter m => SchemaName -> TableName -> [(JobRead payload, Text)] -> m Int64

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> [(JobRead payload, Text)]

List of (job, error message) pairs

-> m Int64 

moveToDLQ over a batch, each job under its own error message. Jobs another worker reclaimed are skipped. Returns the number moved.

Source #retryFromDLQ :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> Int64 -> m (Maybe (JobRead payload))

Arguments

:: forall m payload. (JobPayload payload, MonadArbiter m) 
=> SchemaName

Schema name

-> TableName

Table name

-> Int64

DLQ job id

-> m (Maybe (JobRead payload)) 

Retry a job from the DLQ, re-inserting it with a fresh attempt count. The dedup key is left behind.

Source #dlqJobExists :: MonadArbiter m => Text -> Text -> Int64 -> m Bool

Whether a DLQ job with the given id exists.

Source #listDLQJobs :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> Int -> Int -> m [DLQJob payload]

Arguments

:: forall m payload. (JobPayload payload, MonadArbiter m) 
=> SchemaName

Schema name

-> TableName

Table name

-> Int

Limit

-> Int

Offset

-> m [DLQJob payload] 

List DLQ jobs, most recently failed first.

Source #listDLQJobsByParent :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> Int64 -> Int -> Int -> m [DLQJob payload]

Arguments

:: forall m payload. (JobPayload payload, MonadArbiter m) 
=> SchemaName

Schema name

-> TableName

Table name

-> Int64

Parent job id

-> Int

Limit

-> Int

Offset

-> m [DLQJob payload] 

List a parent's DLQ'd children, most recently failed first.

Source #countDLQJobsByParent :: MonadArbiter m => SchemaName -> TableName -> Int64 -> m Int64

Count DLQ jobs matching a parent_id.

Source #deleteDLQJob :: MonadArbiter m => SchemaName -> TableName -> Int64 -> m Int64

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> Int64

DLQ job id

-> m Int64 

Delete a DLQ job, resuming its parent when no sibling is left.

Source #deleteDLQJobsBatch :: MonadArbiter m => SchemaName -> TableName -> [Int64] -> m Int64

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> [Int64]

DLQ job ids

-> m Int64 

Delete multiple jobs from the dead letter queue, resuming any parents left childless. Returns the total number of DLQ jobs deleted.

Source #deleteCancelledJobs :: MonadArbiter m => SchemaName -> TableName -> Maybe UUID -> [Int64] -> m [Int64]

Delete force-cancel-flagged jobs owner holds or no live lease holds, resuming any parents left childless. Returns the ids it deleted.

Completed-Job Archive

Source #listArchiveJobs :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> Int -> Int -> m [ArchiveJob payload]

List archived jobs (most recent first).

Source #listArchiveFiltered :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> [JobFilter] -> Maybe ArchiveSortColumn -> Maybe SortDir -> Int -> Int -> m [ArchiveJob payload]

Arguments

:: forall m payload. (JobPayload payload, MonadArbiter m) 
=> SchemaName 
-> TableName 
-> [JobFilter] 
-> Maybe ArchiveSortColumn 
-> Maybe SortDir 
-> Int

Limit

-> Int

Offset

-> m [ArchiveJob payload] 

List archived (completed) jobs with composable filters and a typed sort (defaulting to most recent first).

Source #getArchivedJobById :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> Int64 -> m (Maybe (ArchiveJob payload))

Fetch a single archived job by its original job id.

Source #listArchivedJobsByGroupKey :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> Text -> Int -> Int -> m [ArchiveJob payload]

List archived jobs in a group, most recent first.

Source #countArchiveFiltered :: MonadArbiter m => SchemaName -> TableName -> [JobFilter] -> m Int64

Count archived jobs with composable filters.

Source #purgeArchives :: MonadArbiter m => SchemaName -> [TableName] -> m (Int64, [Text])

Purge expired archived jobs across all queues. Each row uses its archive_expires_at value. Return the total rows purged and queues with errors. Run one small batch at each reaper tick.

Source #deleteArchiveJob :: MonadArbiter m => SchemaName -> TableName -> Int64 -> m Int64

Delete one archived job by its archive primary key. Returns rows deleted.

Source #deleteArchiveJobsBatch :: MonadArbiter m => SchemaName -> TableName -> [Int64] -> m Int64

Delete archived jobs by archive primary key. Returns rows deleted.

Source #reEnqueueFromArchive :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> Int64 -> m (Maybe (JobRead payload))

Re-enqueue an archived job as a fresh standalone job, keeping the archive row. Returns the new job, or Nothing when the archive row no longer exists.

Source #updateArchiveResult :: MonadArbiter m => SchemaName -> TableName -> Int64 -> Value -> m Int64

Store a completed root job's result on its archive row. No-ops when the job was not archived. Returns rows updated.

Source #updateArchiveResultsBatch :: MonadArbiter m => SchemaName -> TableName -> [(Int64, Value)] -> m Int64

updateArchiveResult for several (job id, result) pairs in one statement.

Filtered Query Operations

Source #buildWhereClause :: [JobFilter] -> Query ()

The WHERE clause a set of filters narrows a listing by. Empty for no filters.

Source #listJobsFiltered :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> [JobFilter] -> Int -> Int -> m [JobRead payload]

Arguments

:: forall m payload. (JobPayload payload, MonadArbiter m) 
=> SchemaName

Schema name

-> TableName

Table name

-> [JobFilter]

Composable filters

-> Int

Limit

-> Int

Offset

-> m [JobRead payload] 

List filtered jobs, newest first.

Source #listJobsFilteredOrdered :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> [JobFilter] -> Maybe JobSortColumn -> Maybe SortDir -> Int -> Int -> m [JobRead payload]

Arguments

:: forall m payload. (JobPayload payload, MonadArbiter m) 
=> SchemaName

Schema name

-> TableName

Table name

-> [JobFilter]

Composable filters

-> Maybe JobSortColumn

Sort column (defaults to JsId)

-> Maybe SortDir

Sort direction (defaults to SortDesc)

-> Int

Limit

-> Int

Offset

-> m [JobRead payload] 

List filtered jobs under an explicit sort spec. Nothing for both sort arguments orders by id DESC.

Source #listJobsWithStatus :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> [JobFilter] -> Maybe JobSortColumn -> Maybe SortDir -> Int -> Int -> m [(JobRead payload, JobStatus)]

listJobsFilteredOrdered that also returns each job's derived status.

Source #countJobsFiltered :: MonadArbiter m => SchemaName -> TableName -> [JobFilter] -> m Int64

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> [JobFilter]

Composable filters

-> m Int64 

Count jobs with composable filters.

Source #listDLQFiltered :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> [JobFilter] -> Int -> Int -> m [DLQJob payload]

Arguments

:: forall m payload. (JobPayload payload, MonadArbiter m) 
=> SchemaName

Schema name

-> TableName

Table name

-> [JobFilter]

Composable filters

-> Int

Limit

-> Int

Offset

-> m [DLQJob payload] 

List filtered DLQ jobs, most recently failed first.

Source #listDLQFilteredOrdered :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> [JobFilter] -> Maybe DLQSortColumn -> Maybe SortDir -> Int -> Int -> m [DLQJob payload]

Arguments

:: forall m payload. (JobPayload payload, MonadArbiter m) 
=> SchemaName

Schema name

-> TableName

Table name

-> [JobFilter]

Composable filters

-> Maybe DLQSortColumn

Sort column (defaults to DlqFailedAt)

-> Maybe SortDir

Sort direction (defaults to SortDesc)

-> Int

Limit

-> Int

Offset

-> m [DLQJob payload] 

List filtered DLQ jobs under an explicit sort spec. Nothing for both sort arguments orders by failed_at DESC.

Source #countDLQFiltered :: MonadArbiter m => SchemaName -> TableName -> [JobFilter] -> m Int64

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> [JobFilter]

Composable filters

-> m Int64 

Count DLQ jobs with composable filters.

Admin Operations

Source #listJobs :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> Int -> Int -> m [JobRead payload]

Arguments

:: forall m payload. (JobPayload payload, MonadArbiter m) 
=> SchemaName

Schema name

-> TableName

Table name

-> Int

Limit

-> Int

Offset

-> m [JobRead payload] 

List jobs, newest first.

Source #jobExists :: MonadArbiter m => SchemaName -> TableName -> Int64 -> m Bool

Whether a job with the given id exists in the table, without decoding it.

Source #getJobById :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> Int64 -> m (Maybe (JobRead payload))

Arguments

:: forall m payload. (JobPayload payload, MonadArbiter m) 
=> SchemaName

Schema name

-> TableName

Table name

-> Int64

Job id

-> m (Maybe (JobRead payload)) 

Fetch a job by id.

Source #getJobByIdWithStatus :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> Int64 -> m (Maybe (JobRead payload, JobStatus))

getJobById that also returns the job's derived status.

Source #getJobByDedupKey :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> Text -> m (Maybe (JobRead payload))

Get a single job by its dedup key.

Source #getJobsByGroup :: forall m payload. (JobPayload payload, MonadArbiter m) => SchemaName -> TableName -> Text -> Int -> Int -> m [JobRead payload]

Arguments

:: forall m payload. (JobPayload payload, MonadArbiter m) 
=> SchemaName

Schema name

-> TableName

Table name

-> Text

Group key

-> Int

Limit

-> Int

Offset

-> m [JobRead payload] 

Get all jobs for a specific group key.

Source #cancelJob :: MonadArbiter m => Text -> TableName -> Int64 -> m Int64

Arguments

:: MonadArbiter m 
=> Text

Schema name

-> TableName

Table name

-> Int64

Job id

-> m Int64 

Delete a job by id. Returns 0 for a job with children, which cancelJobCascade takes. A deleted child with no siblings left resumes its parent for a completion round.

Source #cancelJobsBatch :: MonadArbiter m => Text -> TableName -> [Int64] -> m Int64

Arguments

:: MonadArbiter m 
=> Text

Schema name

-> TableName

Table name

-> [Int64]

Job ids

-> m Int64 

cancelJob over several ids in one transaction. The last sibling cancelled finds the parent childless and resumes it. Locks the union of parents and rows first. Returns the number deleted.

Source #promoteJob :: MonadArbiter m => SchemaName -> TableName -> Int64 -> m Int64

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> Int64

Job id

-> m Int64

Number of rows updated

Make a delayed or retrying job immediately visible. Refuses an in-flight job.

Source #data QueueStats

Per-status breakdown of a queue. The per-status counts partition the queue and sum to totalJobs, mirroring the derived job status taxonomy.

Constructors

QueueStats 

Fields

Instances

Instances details
FromJSON QueueStats Source # 
Instance details

Defined in Arbiter.Core.Operations

ToJSON QueueStats Source # 
Instance details

Defined in Arbiter.Core.Operations

Eq QueueStats Source # 
Instance details

Defined in Arbiter.Core.Operations

Generic QueueStats Source # 
Instance details

Defined in Arbiter.Core.Operations

Associated Types

type Rep QueueStats 
Instance details

Defined in Arbiter.Core.Operations

type Rep QueueStats = D1 ('MetaData "QueueStats" "Arbiter.Core.Operations" "arbiter-core-0.1.0.0-inplace" 'False) (C1 ('MetaCons "QueueStats" 'PrefixI 'True) (((S1 ('MetaSel ('Just "totalJobs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64) :*: (S1 ('MetaSel ('Just "readyJobs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64) :*: S1 ('MetaSel ('Just "inFlightJobs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64))) :*: (S1 ('MetaSel ('Just "scheduledJobs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64) :*: (S1 ('MetaSel ('Just "backoffJobs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64) :*: S1 ('MetaSel ('Just "throttledJobs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64)))) :*: ((S1 ('MetaSel ('Just "suspendedJobs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64) :*: (S1 ('MetaSel ('Just "cancelledJobs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64) :*: S1 ('MetaSel ('Just "oldestReadyAgeSeconds") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Double)))) :*: (S1 ('MetaSel ('Just "oldestInFlightAgeSeconds") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Double)) :*: (S1 ('MetaSel ('Just "dlqJobs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64) :*: S1 ('MetaSel ('Just "kindCounts") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map Text Int64)))))))
Show QueueStats Source # 
Instance details

Defined in Arbiter.Core.Operations

type Rep QueueStats Source # 
Instance details

Defined in Arbiter.Core.Operations

type Rep QueueStats = D1 ('MetaData "QueueStats" "Arbiter.Core.Operations" "arbiter-core-0.1.0.0-inplace" 'False) (C1 ('MetaCons "QueueStats" 'PrefixI 'True) (((S1 ('MetaSel ('Just "totalJobs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64) :*: (S1 ('MetaSel ('Just "readyJobs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64) :*: S1 ('MetaSel ('Just "inFlightJobs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64))) :*: (S1 ('MetaSel ('Just "scheduledJobs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64) :*: (S1 ('MetaSel ('Just "backoffJobs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64) :*: S1 ('MetaSel ('Just "throttledJobs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64)))) :*: ((S1 ('MetaSel ('Just "suspendedJobs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64) :*: (S1 ('MetaSel ('Just "cancelledJobs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64) :*: S1 ('MetaSel ('Just "oldestReadyAgeSeconds") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Double)))) :*: (S1 ('MetaSel ('Just "oldestInFlightAgeSeconds") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Double)) :*: (S1 ('MetaSel ('Just "dlqJobs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64) :*: S1 ('MetaSel ('Just "kindCounts") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map Text Int64)))))))

Source #statsRowCodec :: RowCodec QueueStats

Decodes the single aggregate row produced by getQueueStatsSQL, whose select list is built from these same columns.

Source #queueStatusCounts :: QueueStats -> [(JobStatus, Int64)]

The per-status depths a QueueStats carries.

Source #data QueueOverview

A landing-overview row: a queue's stats plus its pause state.

Instances

Instances details
FromJSON QueueOverview Source # 
Instance details

Defined in Arbiter.Core.Operations

ToJSON QueueOverview Source # 
Instance details

Defined in Arbiter.Core.Operations

Eq QueueOverview Source # 
Instance details

Defined in Arbiter.Core.Operations

Generic QueueOverview Source # 
Instance details

Defined in Arbiter.Core.Operations

Associated Types

type Rep QueueOverview 
Instance details

Defined in Arbiter.Core.Operations

type Rep QueueOverview = D1 ('MetaData "QueueOverview" "Arbiter.Core.Operations" "arbiter-core-0.1.0.0-inplace" 'False) (C1 ('MetaCons "QueueOverview" 'PrefixI 'True) ((S1 ('MetaSel ('Just "overviewQueue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "overviewStats") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 QueueStats)) :*: (S1 ('MetaSel ('Just "overviewQueuePaused") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: (S1 ('MetaSel ('Just "overviewWorkersLive") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64) :*: S1 ('MetaSel ('Just "overviewWorkersPaused") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64)))))
Show QueueOverview Source # 
Instance details

Defined in Arbiter.Core.Operations

type Rep QueueOverview Source # 
Instance details

Defined in Arbiter.Core.Operations

type Rep QueueOverview = D1 ('MetaData "QueueOverview" "Arbiter.Core.Operations" "arbiter-core-0.1.0.0-inplace" 'False) (C1 ('MetaCons "QueueOverview" 'PrefixI 'True) ((S1 ('MetaSel ('Just "overviewQueue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "overviewStats") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 QueueStats)) :*: (S1 ('MetaSel ('Just "overviewQueuePaused") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: (S1 ('MetaSel ('Just "overviewWorkersLive") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64) :*: S1 ('MetaSel ('Just "overviewWorkersPaused") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64)))))

Source #getQueueStats :: MonadArbiter m => SchemaName -> TableName -> [Text] -> m QueueStats

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> [Text]

The labels the payload declares. kindCounts covers these labels.

-> m QueueStats 

A queue's per-status counts and backlog ages.

Source #getAllQueueStats :: MonadArbiter m => SchemaName -> [(TableName, [Text])] -> m [QueueOverview]

Arguments

:: MonadArbiter m 
=> SchemaName 
-> [(TableName, [Text])]

Each queue with the labels its payload declares.

-> m [QueueOverview] 

Every queue's stats plus pause state in one query, for the landing overview.

Count Operations

Source #countJobs :: MonadArbiter m => SchemaName -> TableName -> m Int64

Count every job in a table.

Source #countJobsByGroup :: MonadArbiter m => SchemaName -> TableName -> Text -> m Int64

Count a group's jobs.

Source #countDLQJobs :: MonadArbiter m => SchemaName -> TableName -> m Int64

Count a queue's DLQ jobs.

Parent-Child Operations

Source #getJobsByParent :: forall m payload. (JobPayload payload, MonadArbiter m) => Text -> TableName -> Int64 -> Int -> Int -> m [JobRead payload]

Arguments

:: forall m payload. (JobPayload payload, MonadArbiter m) 
=> Text

Schema name

-> TableName

Table name

-> Int64

Parent id

-> Int

Limit

-> Int

Offset

-> m [JobRead payload] 

List jobs filtered by parent_id with pagination.

Source #countJobsByParent :: MonadArbiter m => SchemaName -> TableName -> Int64 -> m Int64

Count jobs matching a parent_id.

Source #countChildrenBatch :: MonadArbiter m => SchemaName -> TableName -> [Int64] -> m (Map Int64 (Int64, Int64))

Child counts as (total, paused) per parent id, over a batch. Parents with none are absent.

Source #countDLQChildrenBatch :: MonadArbiter m => SchemaName -> TableName -> [Int64] -> m (Map Int64 Int64)

DLQ child counts per parent id, over a batch. Parents with none are absent.

Job Dependency Operations

Source #pauseChildren :: MonadArbiter m => Text -> TableName -> Int64 -> m Int64

Arguments

:: MonadArbiter m 
=> Text

Schema name

-> TableName

Table name

-> Int64

Parent job id

-> m Int64 

Suspend a parent's claimable children. In-flight ones are left alone. Returns the number suspended.

Source #resumeChildren :: MonadArbiter m => Text -> TableName -> Int64 -> m Int64

Arguments

:: MonadArbiter m 
=> Text

Schema name

-> TableName

Table name

-> Int64

Parent job id

-> m Int64 

Resume a parent's suspended children. Returns the number resumed.

Source #cancelJobCascade :: MonadArbiter m => Text -> TableName -> Int64 -> m Int64

Arguments

:: MonadArbiter m 
=> Text

Schema name

-> TableName

Table name

-> Int64

Root job id

-> m Int64 

Delete a job and every descendant under it, resuming the parent of a root that is itself a child. Returns the number deleted.

Source #cancelJobTree :: MonadArbiter m => Text -> TableName -> Int64 -> m Int64

Arguments

:: MonadArbiter m 
=> Text

Schema name

-> TableName

Table name

-> Int64

Any job id in the tree

-> m Int64 

Delete a whole job tree, named by any node in it. Walks up to the root, then deletes from there down. The root has no parent to resume. Returns the number deleted.

Source #forceCancelJob :: MonadArbiter m => Text -> TableName -> Int64 -> m Int64

Arguments

:: MonadArbiter m 
=> Text

Schema name

-> TableName

Table name

-> Int64

Root job id

-> m Int64 

Cascade-cancel a job subtree. Flags still-live claimed jobs, deletes the rest, and NOTIFYs the queue's cancel channel for every claimed job affected. Workers async-cancel the matching handler thread on receipt.

Suspend/Resume Operations

Source #suspendJob :: MonadArbiter m => Text -> TableName -> Int64 -> m Int64

Arguments

:: MonadArbiter m 
=> Text

Schema name

-> TableName

Table name

-> Int64

Job id

-> m Int64 

Suspend a job, making it unclaimable. Refuses an in-flight job.

Source #resumeJob :: MonadArbiter m => Text -> TableName -> Int64 -> m Int64

Arguments

:: MonadArbiter m 
=> Text

Schema name

-> TableName

Table name

-> Int64

Job id

-> m Int64 

Resume a suspended job, making it claimable again.

Groups Table Operations

Source #data GroupsCursor

Where a queue's next groups pass resumes. The summary window and the emptied scan walk the key space independently.

Source #data GroupsPass

What one queue's groups pass did: the rows it rewrote, whether its missing-summary repair threw, and where the next pass resumes.

Source #refreshGroupsForQueue :: MonadArbiter m => SchemaName -> TableName -> Int -> Maybe GroupsCursor -> m GroupsPass

Arguments

:: MonadArbiter m 
=> SchemaName 
-> TableName 
-> Int

Rows this pass covers.

-> Maybe GroupsCursor

Resume past these keys, or start at the first.

-> m GroupsPass 

Recompute the groups table from the main queue, over one bounded batch of rows past cursor. Locks the window's groups rows and the emptied ones (FOR UPDATE SKIP LOCKED), then rewrites them, which deletes the emptied. The missing-summary repair runs in its own transaction. The caller owns any cross-pool coordination (see runGatedState and refreshAllGroups).

Source #refreshAllGroups :: MonadArbiter m => SchemaName -> [TableName] -> Map TableName GroupsCursor -> m ((Int64, [Text]), Map TableName GroupsCursor)

Arguments

:: MonadArbiter m 
=> SchemaName 
-> [TableName] 
-> Map TableName GroupsCursor

Where the previous pass left off, per queue.

-> m ((Int64, [Text]), Map TableName GroupsCursor) 

Schema-wide groups-table refresh, groupsRefreshBatch rows for the pass. Wrap in runGatedState so one pool runs it per interval and every pool resumes from the same cursors. A caller that discards the cursors refreshes the same head of each table forever. Each queue runs in a savepoint. One queue's failure leaves the rest. Its row locks stand until the caller's transaction ends. Returns the rows rewritten, the queue names that failed or whose repair failed, and where each queue resumes.

Source #refreshAllGroupsFully :: MonadArbiter m => SchemaName -> [TableName] -> m (Int64, [Text])

Run refreshAllGroups until it scans each queue's complete groups table. Use one batch and transaction for each pass. This is a repair operation. The reaper runs one batch at each tick.

Source #sweepExhaustedJobs :: MonadArbiter m => SchemaName -> [TableName] -> m (Int64, [Text])

Sweep exhausted jobs across all queues. Returns the total moved and the names of queues whose sweep failed.

Source #sweepCancelledJobs :: MonadArbiter m => SchemaName -> [TableName] -> m (Int64, [Text])

Sweep force-cancel-flagged jobs whose lease has lapsed across all queues. A live worker's jobs are left for the worker's own cancel handler. Returns the total deleted and the names of queues whose sweep failed.

Cron Schedule Operations

Source #upsertCronDefault :: MonadArbiter m => SchemaName -> Text -> Text -> Text -> Text -> Maybe Text -> m Int64

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> Text

Schedule name

-> Text

Queue name

-> Text

Default cron expression

-> Text

Default overlap policy

-> Maybe Text

Default IANA tz name (Nothing = UTC).

-> m Int64 

Upsert a cron schedule's default expression and overlap policy, preserving user overrides and the enabled flag. queue_name is overwritten on conflict.

Source #listCronSchedules :: MonadArbiter m => SchemaName -> Maybe Text -> m [CronScheduleRow]

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> Maybe Text

Queue filter. Nothing returns schedules for all queues.

-> m [CronScheduleRow] 

List cron schedules ordered by name, optionally filtered by queue.

Source #getCronScheduleByName :: MonadArbiter m => SchemaName -> Text -> m (Maybe CronScheduleRow)

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> Text

Schedule name

-> m (Maybe CronScheduleRow) 

Get a single cron schedule by name.

Source #updateCronSchedule :: MonadArbiter m => SchemaName -> Text -> CronScheduleUpdate -> m Int64

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> Text

Schedule name

-> CronScheduleUpdate 
-> m Int64 

Patch a cron schedule. Returns rows affected, 0 for a name that is not there.

Source #touchCronLastFired :: MonadArbiter m => SchemaName -> Text -> m Int64

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> Text

Schedule name

-> m Int64 

Update last_fired_at to NOW() for a cron schedule.

Source #touchCronChecked :: MonadArbiter m => SchemaName -> UTCTime -> [Text] -> m Int64

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> UTCTime

Watermark (the minute the scheduler is advancing to)

-> [Text]

Schedule names

-> m Int64 

Advance last_checked_at to the supplied watermark for the given cron schedule names. The watermark is the minute boundary the scheduler finished evaluating. A wrapping GREATEST in the SQL keeps the column monotonic when concurrent worker pools race.

Source #tryFireCronGate :: MonadArbiter m => SchemaName -> Text -> UTCTime -> m Bool

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> Text

Schedule name

-> UTCTime

Minute floor for the tick being attempted

-> m Bool 

Claim a minute floor for a schedule. True when the caller proceeds with the insert. False when another pool fired this minute.

Source #tryAcquireCronLeader :: MonadArbiter m => SchemaName -> Text -> Text -> m Bool

Arguments

:: MonadArbiter m 
=> SchemaName 
-> Text

Queue name

-> Text

Schedule name

-> m Bool 

Try to acquire the (schema, queue, name) cron leader lock. Must be inside a transaction.

Source #requestCronRun :: MonadArbiter m => SchemaName -> Text -> m RunRequestOutcome

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> Text

Schedule name

-> m RunRequestOutcome 

Stamp a manual run request on an enabled schedule and NOTIFY the run-now channel. A pending, unexpired request is left as it stands.

Source #claimCronRun :: MonadArbiter m => SchemaName -> Text -> m (Maybe CronScheduleRow)

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> Text

Schedule name

-> m (Maybe CronScheduleRow) 

Claim a pending run request, returning the claimed row. Nothing when another pool won the claim or the schedule is disabled.

Source #touchCronManualRun :: MonadArbiter m => SchemaName -> UTCTime -> Text -> m Int64

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> UTCTime

When the manual run fired

-> Text

Schedule name

-> m Int64 

Record when a manual run last fired a job for a cron schedule.

Source #pendingCronRuns :: MonadArbiter m => SchemaName -> [Text] -> m [Text]

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> [Text]

Schedule names

-> m [Text] 

Enabled schedules among names that have a pending run request.

Worker Registry Operations

Source #registerWorker :: MonadArbiter m => SchemaName -> UUID -> Text -> Maybe Text -> Maybe Int32 -> NominalDiffTime -> Maybe Value -> m (Maybe Bool)

Register or refresh a worker and return its effective paused state.

Source #heartbeatWorker :: MonadArbiter m => SchemaName -> UUID -> m (Maybe Bool)

Record a heartbeat and return the worker's effective paused state.

Source #setWorkerPaused :: MonadArbiter m => SchemaName -> UUID -> Bool -> m Int64

Set a worker's pause flag.

Source #markWorkerShuttingDown :: MonadArbiter m => SchemaName -> UUID -> m Int64

Mark a worker as gracefully draining.

Source #deregisterWorker :: MonadArbiter m => SchemaName -> UUID -> m Int64

Remove a worker registry row.

Source #workerRegistered :: MonadArbiter m => SchemaName -> UUID -> m Bool

Whether the worker registry holds this identity.

Source #listWorkers :: MonadArbiter m => SchemaName -> Maybe Text -> Maybe NominalDiffTime -> m [WorkerRow]

List workers, optionally filtered by queue and heartbeat age.

Source #sweepStaleWorkers :: MonadArbiter m => SchemaName -> m Int64

Delete workers older than their recorded stale threshold.

Queue Operations

Source #ensureQueue :: MonadArbiter m => SchemaName -> Text -> m Int64

Arguments

:: MonadArbiter m 
=> SchemaName 
-> Text

Queue name

-> m Int64 

Insert an arbiter_queues row with defaults when absent.

Source #setQueuePaused :: MonadArbiter m => SchemaName -> Text -> Bool -> m Int64

Arguments

:: MonadArbiter m 
=> SchemaName 
-> Text

Queue name

-> Bool 
-> m Int64 

Set the queue's paused flag, creating the row if missing.

Source #getQueue :: MonadArbiter m => SchemaName -> Text -> m (Maybe QueueRow)

Arguments

:: MonadArbiter m 
=> SchemaName 
-> Text

Queue name

-> m (Maybe QueueRow) 

Get the arbiter_queues row for a single queue. Nothing when absent.

Source #listQueues :: MonadArbiter m => SchemaName -> m [QueueRow]

List all arbiter_queues rows, ordered by queue name.

Global Gate Operations

Source #runGated :: MonadArbiter m => SchemaName -> Text -> NominalDiffTime -> m a -> m (Maybe a)

Arguments

:: MonadArbiter m 
=> SchemaName 
-> Text

Task identifier (used as the gate row key).

-> NominalDiffTime

Minimum interval between runs, in seconds.

-> m a

Work to perform when this caller wins the gate.

-> m (Maybe a) 

Run work at most once per interval across every worker pool sharing the same schema, keyed by task. Uses a watermark row in arbiter_gates claimed via SELECT FOR UPDATE SKIP LOCKED. Returns Just the work's result when it ran. Returns Nothing when the gate is too recent or another pool holds the task.

Source #runGatedBounded :: MonadArbiter m => SchemaName -> Text -> NominalDiffTime -> NominalDiffTime -> m a -> m (Maybe a)

runGated with each statement of work bounded by limit. The bound is transaction-local.

Source #runGatedShared :: (FromJSON a, MonadArbiter m, ToJSON a) => SchemaName -> Text -> NominalDiffTime -> NominalDiffTime -> m a -> m (Maybe (Shared a))

Arguments

:: (FromJSON a, MonadArbiter m, ToJSON a) 
=> SchemaName 
-> Text 
-> NominalDiffTime

Minimum interval between runs.

-> NominalDiffTime

How long a published result stands.

-> m a 
-> m (Maybe (Shared a)) 

Run gated work or read a result published by another caller. Return Nothing if there is no result newer than maxAge. The work starts after the gate transaction commits. A slow operation does not retain the gate row or a read snapshot. The exclusion interval starts after publication. A failed operation or publication restores the watermark and permits another caller to run. The compensation period is limited to interval.

Source #runGatedState :: (FromJSON s, MonadArbiter m, ToJSON s) => SchemaName -> Text -> NominalDiffTime -> (Maybe s -> m (a, s)) -> m (Maybe a)

runGated where the task resumes from the state its last run left in the gate row, read under the claim and written with the watermark. A payload that no longer parses reads as no state.

Source #runGatedStateBounded :: (FromJSON s, MonadArbiter m, ToJSON s) => SchemaName -> Text -> NominalDiffTime -> NominalDiffTime -> (Maybe s -> m (a, s)) -> m (Maybe a)

runGatedState with each statement of work bounded by limit.

Source #setLocalStatementTimeout :: MonadArbiter m => NominalDiffTime -> m ()

Set a wall-clock limit for statements in the current transaction. The database aborts a statement that exceeds the limit.

Source #micros :: NominalDiffTime -> Int

An interval in microseconds, for the timeout and delay primitives.

Source #gateNameFor :: MonadArbiter m => Text -> [Text] -> m Text

A gate name for a set of parts. The sorted set itself while it fits the gate's key, an md5 digest of it beyond that.

Source #data Shared a

Where a shared result came from.

Constructors

Ran a

Result from work run by this caller.

Published Double a

Result read from the gate, with its age in seconds.

Unreadable Text

A published result this caller could not decode, with the parse error.

Instances

Instances details
Functor Shared Source # 
Instance details

Defined in Arbiter.Core.Operations.Gates

Methods

#fmap :: (a -> b) -> Shared a -> Shared b

#(<$) :: a -> Shared b -> Shared a

Eq a => Eq (Shared a) Source # 
Instance details

Defined in Arbiter.Core.Operations.Gates

Methods

#(==) :: Shared a -> Shared a -> Bool

#(/=) :: Shared a -> Shared a -> Bool

Show a => Show (Shared a) Source # 
Instance details

Defined in Arbiter.Core.Operations.Gates

Methods

#showsPrec :: Int -> Shared a -> ShowS

#show :: Shared a -> String

#showList :: [Shared a] -> ShowS

Internal Operations

Source #getParentStateSnapshot :: MonadArbiter m => SchemaName -> TableName -> Int64 -> m (Maybe Value)

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> Int64

Job id

-> m (Maybe Value) 

Read a job's raw parent_state snapshot, which a DLQ-retried finalizer comes back carrying.

Source #readChildResultsRaw :: MonadArbiter m => SchemaName -> TableName -> Int64 -> m (Map Int64 Value, Map Int64 Text, Maybe Value, Map Int64 Text)

Arguments

:: MonadArbiter m 
=> SchemaName

Schema name

-> TableName

Table name

-> Int64

Parent job id

-> m (Map Int64 Value, Map Int64 Text, Maybe Value, Map Int64 Text) 

Read child results, DLQ errors, and the parent_state snapshot for a rollup finalizer in a single query.

Source #mergeRawChildResults :: Map Int64 Value -> Map Int64 Text -> Maybe Value -> Map Int64 (Either Text Value)

Merge child results, DLQ errors and the snapshot, left-biased in that order.