arbiter-core-0.1.0.0
arbiter-core
Safe HaskellNone
LanguageGHC2024

Arbiter.Core.Concurrency.Spec

Description

Internal to the arbiter packages. Not covered by the PVP.

Per-job concurrency limits. A payload's concurrencyFor describes how to select a policy and key. Static inspection finds all policies that the migration must initialize. Each selected policy supplies the limit.

Synopsis

Core types

data ConcurrencyKeySource #

A resolved concurrency key with a policy prefix and per-key suffix. The stored form is prefix:suffix.

Constructors

ConcurrencyKey 

Fields

toConcurrencyKey :: Text -> Text -> ConcurrencyKeySource #

A concurrency key from its prefix and suffix.

concurrencyKeyText :: ConcurrencyKey -> TextSource #

The stored key text, prefix:suffix.

data ConcurrencyPolicySource #

A concurrency policy. At most cpLimit jobs are in flight per key under cpPrefix. The default is seeded. An operator override on the policy takes precedence.

Constructors

ConcurrencyPolicy 

Fields

  • cpPrefix :: Text

    The key prefix. It must not contain :.

  • cpLimit :: Int32

    The default in-flight limit per key, in jobs. The migration rejects a declared limit below 1.

concurrencyPolicy :: Text -> Int32 -> ConcurrencyPolicySource #

A policy named prefix admitting at most limit concurrent jobs per key. The cap is floored at 1. Pause it with setConcurrencyLimit policy {cpLimit = 0}. The prefix must not contain :, the key separator. The migration enforces this.

Selecting a policy per job

class HasConcurrency payload whereSource #

A payload's per-job policy selection. Defaults to unbounded. Only capped payloads need an instance.

Minimal complete definition

Nothing

Methods

concurrencyFor :: ConcurrencyFor payloadSource #

The selector deciding which policy (if any) caps a given job.

Instances

Instances details
HasConcurrency payload Source # 
Instance details

Defined in Arbiter.Core.Concurrency.Spec

type ConcurrencyFor payload = Selector ConcurrencyPolicy payload (Maybe ConcurrencyKey)Source #

A selective description of the concurrency key for a payload. Evaluation returns the job key. Static inspection returns the reachable policies.

noConcurrency :: ConcurrencyFor payloadSource #

This payload is unbounded.

concurrencyBy :: ConcurrencyPolicy -> (payload -> Text) -> ConcurrencyFor payloadSource #

Cap by a fixed policy, keyed by a per-job suffix, such as a tenant id.

globalConcurrency :: ConcurrencyPolicy -> Text -> ConcurrencyFor payloadSource #

Cap by a fixed policy under one shared key.

chooseWhen :: (payload -> Bool) -> Selector policy payload a -> Selector policy payload a -> Selector policy payload aSource #

The first selector when the predicate holds, else the second. Policy collection inspects both branches.

concurrencyByCase :: (Bounded k, Enum k, Eq k) => (payload -> k) -> (k -> ConcurrencyFor payload) -> ConcurrencyFor payloadSource #

N-way chooseWhen. Maps the job to a finite tag, then each tag to its selector. Policy collection evaluates every tag in [minBound..maxBound]. The tag's Bounded/Enum and the selector must be total over k.

collectPolicies :: Ord policy => Selector policy payload a -> Set policySource #

All policies that a selector can reach across all branches.

Registry reflection

type RegistryConcurrencyPolicies (registry :: JobPayloadRegistry) = RegistryPolicies registry ConcurrencyPolicySource #

The constraint that lets the migration collect a registry's declared policies.

registryConcurrencyPolicies :: forall (registry :: JobPayloadRegistry). RegistryConcurrencyPolicies registry => Set ConcurrencyPolicySource #

Every distinct policy declared across the registry's payloads.

registryConcurrencyTables :: forall (registry :: JobPayloadRegistry). RegistryConcurrencyPolicies registry => [(Text, Bool)]Source #

Each registry table paired with whether its payload declares any policy.