Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Payload Kinds

A payload kind is an optional Text label stored with each job at insert. Label Use lists where it appears.

HasKind has two members:

MemberTypeDescription
kindOfpayload -> Maybe TextThe label for a payload.
kindsFor[Text]Every label kindOf can return.

With no instance for the payload, kindOf returns Nothing and kindsFor is [].

Constructor Labels

The default methods use constructor names. Derive Generic and declare an empty instance:

data EmailPayload
  = SendWelcome UserId
  | SendReceipt OrderId
  deriving stock (Generic)

instance HasKind EmailPayload

kindOf (SendReceipt 7) is Just "SendReceipt". kindsFor @EmailPayload is ["SendWelcome", "SendReceipt"].

Custom Labels

Implement both members for other labels:

data EmailKind = Welcome | Receipt | PasswordReset
  deriving stock (Bounded, Enum, Show)

emailKindText :: EmailKind -> Text
emailKindText = T.toLower . T.pack . show

data EmailPayload = EmailPayload
  { emailKind :: EmailKind
  , emailTo :: Text
  }

instance HasKind EmailPayload where
  kindOf = Just . emailKindText . emailKind
  kindsFor = map emailKindText [minBound .. maxBound]

kindOf (EmailPayload Receipt "a@b.c") is Just "receipt". kindsFor @EmailPayload is ["welcome", "receipt", "passwordreset"].

kindsFor must list every label kindOf can return. Kind metrics and kindCounts skip undeclared labels.

Labels from a Nested Type

constructorKind and constructorKinds read the constructors of any Generic type:

data Envelope = Envelope
  { envelopeTraceId :: Text
  , envelopePayload :: EmailPayload
  }

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

Label Use

InterfaceLabel source
GET /api/queues/:queue/jobs?kind= and the DLQ and archive filtersStored job label
GET /api/queues/:queue/kindskindsFor
Admin UI kind columnStored job label
Admin UI kind filterkindsFor
GET /api/queues/:queue/stats field kindCountsStored labels declared by kindsFor
arbiter.queue.depth_by_kindStored labels declared by kindsFor
arbiter.jobs.* metrics and the handler histogramStored labels declared by kindsFor
Producer span attribute arbiter.kindkindOf
Consumer span attribute arbiter.kindStored job label

API details: Arbiter.Core.Job.Kind.