| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Arbiter.Core.QueueRegistry
Description
Type-level utilities for job queue registry validation.
The registry enforces at compile-time that:
- Each payload type maps to exactly one queue name (via
TableForPayload) - All queue names are unique (via
AllQueuesUnique) - Workers can only claim jobs for payloads they're registered to handle
Synopsis
- type JobPayloadRegistry = [(Symbol, Type)]
- type family TableForPayload payload (registry :: JobPayloadRegistry) :: Symbol where ...
- type family AllQueuesUnique (registry :: JobPayloadRegistry) where ...
- class RegistryTables (registry :: JobPayloadRegistry) where
- registryTableNames :: Proxy registry -> [Text]
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
| RegistryTables ('[] :: [(Symbol, Type)]) Source # | |
Defined in Arbiter.Core.QueueRegistry | |
| (KnownSymbol table, RegistryTables rest) => RegistryTables ('(table, payload) ': rest) Source # | |
Defined in Arbiter.Core.QueueRegistry Methods registryTableNames :: Proxy ('(table, payload) ': rest) -> [Text] Source # | |