| 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 AllQueuesUnique registry => 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 #
Look up the table name for a payload type. Compile-time error if 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 #
Compile-time check that no two payload types share a queue name.
Equations
| AllQueuesUnique ('[] :: [(Symbol, Type)]) = () | |
| AllQueuesUnique ('(table, _1) ': rest) = (NotInTables table rest, AllQueuesUnique rest) |
Runtime utilities
class AllQueuesUnique registry => RegistryTables (registry :: JobPayloadRegistry) where Source #
Extract table names from a type-level registry at runtime (used by migrations).
Methods
registryTableNames :: Proxy registry -> [Text] Source #
Instances
| RegistryTables ('[] :: [(Symbol, Type)]) Source # | |
Defined in Arbiter.Core.QueueRegistry | |
| (KnownSymbol table, NotInTables table rest, RegistryTables rest) => RegistryTables ('(table, payload) ': rest) Source # | |
Defined in Arbiter.Core.QueueRegistry Methods registryTableNames :: Proxy ('(table, payload) ': rest) -> [Text] Source # | |