arbiter-core-0.1.0.0: Core types and logic for PostgreSQL-backed job queue
Safe HaskellNone
LanguageGHC2024

Arbiter.Core.QueueRegistry

Description

Type-level utilities for job queue registry validation.

The registry enforces at compile-time that:

  1. Each payload type maps to exactly one queue name (via TableForPayload)
  2. All queue names are unique (via AllQueuesUnique)
  3. Workers can only claim jobs for payloads they're registered to handle
Synopsis

Registry type

type JobPayloadRegistry = [(Symbol, Type)] Source #

A type-level registry mapping table names to payload types.

Example: type MyAppRegistry = '[ '("email_jobs", EmailPayload) , '("image_jobs", ImagePayload) ]

Registry validation

type family TableForPayload payload (registry :: JobPayloadRegistry) :: Symbol where ... Source #

Get the table name for a payload from the registry.

This type family looks up the table name for a given payload type in the registry, providing a compile-time error if the payload is not registered.

Equations

TableForPayload payload ('(table, payload) ': _1) = table 
TableForPayload payload ('(_1, _2) ': rest) = TableForPayload payload rest 
TableForPayload payload ('[] :: [(Symbol, Type)]) = TypeError (('Text "Payload type " ':<>: 'ShowType payload) ':<>: 'Text " not found in registry") :: Symbol 

type family AllQueuesUnique (registry :: JobPayloadRegistry) where ... Source #

Ensure all queue names in a registry are unique

This prevents multiple payload types from mapping to the same queue, which would cause parsing failures when workers claim jobs.

Equations

AllQueuesUnique ('[] :: [(Symbol, Type)]) = () 
AllQueuesUnique ('(table, _1) ': rest) = (NotInTables table rest, AllQueuesUnique rest) 

Runtime utilities

class RegistryTables (registry :: JobPayloadRegistry) where Source #

A typeclass for converting type-level registries to runtime table lists

This allows us to extract the list of table names at runtime for operations like running migrations.

Methods

registryTableNames :: Proxy registry -> [Text] Source #

Get the list of table names as runtime Text values

Instances

Instances details
RegistryTables ('[] :: [(Symbol, Type)]) Source # 
Instance details

Defined in Arbiter.Core.QueueRegistry

Methods

registryTableNames :: Proxy ('[] :: [(Symbol, Type)]) -> [Text] Source #

(KnownSymbol table, RegistryTables rest) => RegistryTables ('(table, payload) ': rest) Source # 
Instance details

Defined in Arbiter.Core.QueueRegistry

Methods

registryTableNames :: Proxy ('(table, payload) ': rest) -> [Text] Source #