| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Arbiter.Core.Job.Schema
Description
SQL generation functions for job queue schemas. No database execution happens here.
Synopsis
- type SchemaName = Text
- type TableName = Text
- createSchemaSQL :: SchemaName -> Text
- defaultSchemaName :: SchemaName
- createJobQueueTableSQL :: Text -> Text -> Text
- createJobQueueDLQTableSQL :: Text -> Text -> Text
- createJobQueueArchiveTableSQL :: Text -> Text -> Text
- queueTableNames :: TableName -> [TableName]
- addTraceContextColumnSQL :: Text -> Text -> Text
- addClaimSeqColumnSQL :: Text -> Text -> Text
- addKindColumnSQL :: Text -> Text -> Text
- setMaxAttemptsDefaultSQL :: SchemaName -> TableName -> Text
- createJobQueueUngroupedReadyRankingIndexSQL :: Text -> Text -> Text
- createJobQueueUngroupedDueIndexSQL :: Text -> Text -> Text
- migrateUngroupedReadySplitIndexesSQL :: Text -> Text -> Text
- createDLQGroupKeyIndexSQL :: Text -> Text -> Text
- createDLQFailedAtIndexSQL :: Text -> Text -> Text
- createDLQParentIdIndexSQL :: Text -> Text -> Text
- createArchiveCompletedAtIndexSQL :: Text -> Text -> Text
- createArchiveExpiresAtIndexSQL :: Text -> Text -> Text
- createArchiveJobIdIndexSQL :: Text -> Text -> Text
- createArchiveParentIdIndexSQL :: Text -> Text -> Text
- createArchiveGroupKeyIndexSQL :: Text -> Text -> Text
- createDedupKeyIndexSQL :: Text -> Text -> Text
- createParentIdIndexSQL :: Text -> Text -> Text
- createNotifyFunctionSQL :: Text -> Text -> Text
- createNotifyTriggerSQL :: Text -> Text -> Text
- dropNotifyTriggerSQL :: Text -> Text -> Text
- dropNotifyFunctionSQL :: Text -> Text -> Text
- createEventStreamingFunctionSQL :: SchemaName -> Text
- createEventStreamingTriggersSQL :: SchemaName -> TableName -> Text
- dropEventStreamingFunctionSQL :: SchemaName -> Text
- dropEventStreamingTriggersSQL :: Text -> Text -> Text
- notificationChannelForTable :: TableName -> Text
- eventStreamingChannel :: Text
- pauseNotifyChannel :: SchemaName -> Text -> Text
- pauseNotifyChannelPrefix :: SchemaName -> Text
- cancelNotifyChannel :: SchemaName -> Text -> Text
- cancelNotifyChannelPrefix :: SchemaName -> Text
- cronRunNotifyChannel :: SchemaName -> Text
- notifyFunctionName :: TableName -> Text
- notifyTriggerName :: TableName -> Text
- eventStreamingFunctionName :: Text
- eventStreamingTriggerName :: TableName -> Text
- eventStreamingDLQTriggerName :: TableName -> Text
- legacyEventStreamingTriggers :: [(Text, Bool)]
- notifyObjectComment :: Text
- notifyObjectCommentPrefix :: Text
- notifyAdoptedObjectComment :: Text
- eventStreamingObjectComment :: Text
- eventStreamingObjectCommentPrefix :: Text
- eventStreamingAdoptedObjectComment :: Text
- qualifiedTable :: SchemaName -> TableName -> Text
- jobQueueTable :: SchemaName -> TableName -> Text
- jobQueueDLQTable :: SchemaName -> TableName -> Text
- jobQueueArchiveTable :: SchemaName -> TableName -> Text
- jobQueueResultsTable :: Text -> Text -> Text
- jobQueueGroupsTable :: Text -> Text -> Text
- createResultsTableSQL :: Text -> Text -> Text
- maintenanceFunctionNames :: Text -> Text -> (Text, Text, Text)
- createMaintenanceTriggersSQL :: Text -> Text -> Text -> Text
- statementTriggerSQL :: Text -> Text -> Text -> Text -> Text -> Text -> Text
Name Types
Source #type SchemaName = Text
PostgreSQL schema name, e.g. "arbiter".
Schema Creation
Source #createSchemaSQL :: SchemaName -> Text
Create the schema arbiter's tables live in.
Source #defaultSchemaName :: SchemaName
The schema arbiter's tables live in by default.
Table Creation SQL
Source #createJobQueueTableSQL :: Text -> Text -> Text
Create a queue's main job table, holding its pending and in-progress jobs.
Source #createJobQueueDLQTableSQL :: Text -> Text -> Text
Create a queue's DLQ table, where a job that runs out of attempts lands as a full snapshot plus its failure metadata.
Source #createJobQueueArchiveTableSQL :: Text -> Text -> Text
Create the completed-job archive table. The table is logged.
Source #queueTableNames :: TableName -> [TableName]
A queue's own table and its companions, unqualified and unquoted, for callers that
match on pg_catalog relnames.
Source #addTraceContextColumnSQL :: Text -> Text -> Text
Add the W3C trace-context columns to a queue's three job tables.
Source #addClaimSeqColumnSQL :: Text -> Text -> Text
Add the per-claim token column to a queue's three job tables.
Source #addKindColumnSQL :: Text -> Text -> Text
Add the payload variant label to a queue's three job tables.
Source #setMaxAttemptsDefaultSQL :: SchemaName -> TableName -> Text
Backfill NULL max_attempts to the default and set the column default.
The column stays nullable for rolling deploys.
Index Creation SQL
Source #createJobQueueUngroupedReadyRankingIndexSQL :: Text -> Text -> Text
Ranking index over ready ungrouped jobs (not_visible_until IS NULL AND NOT
suspended). The claim's ordered LIMIT stops the scan at the first ready rows.
Source #createJobQueueUngroupedDueIndexSQL :: Text -> Text -> Text
Due-finder for ungrouped parked rows. The claim range-scans it by
not_visible_until <= NOW() for due scheduled, backoff and expired-lease jobs.
Source #migrateUngroupedReadySplitIndexesSQL :: Text -> Text -> Text
Replace the full ungrouped ranking index with the ready-only ranking index plus the due-finder.
Source #createDLQGroupKeyIndexSQL :: Text -> Text -> Text
Index on DLQ group_key, for per-group failure listings.
Source #createDLQFailedAtIndexSQL :: Text -> Text -> Text
Index on DLQ failed_at, for the most-recent-first listing.
Source #createDLQParentIdIndexSQL :: Text -> Text -> Text
Index on DLQ parent_id, for per-parent child lookups and counts.
Source #createArchiveCompletedAtIndexSQL :: Text -> Text -> Text
Index on archive completed_at for the most-recent-first history listing.
Source #createArchiveExpiresAtIndexSQL :: Text -> Text -> Text
Index on archive archive_expires_at. Drives the retention purge sweep.
Source #createArchiveJobIdIndexSQL :: Text -> Text -> Text
Index on archive job_id for by-id lookups (getArchivedJobById).
Source #createArchiveParentIdIndexSQL :: Text -> Text -> Text
Index on archive parent_id for per-tree history lookups.
Source #createArchiveGroupKeyIndexSQL :: Text -> Text -> Text
Index on archive group_key for per-group history lookups.
Source #createDedupKeyIndexSQL :: Text -> Text -> Text
Unique index on dedup_key. The dedup ON CONFLICT resolves against it.
Source #createParentIdIndexSQL :: Text -> Text -> Text
Partial index on parent_id, for per-parent child lookups.
NOTIFY Trigger SQL
Source #createNotifyFunctionSQL :: Text -> Text -> Text
SQL for the per-table NOTIFY function, fired once per insert statement. A statement that inserted nothing notifies nothing. Channel name is quoted as a string literal.
Source #createNotifyTriggerSQL :: Text -> Text -> Text
A table's job-arrival NOTIFY trigger. Statement-level. A batch insert notifies one time.
Event Streaming Trigger SQL
Source #createEventStreamingFunctionSQL :: SchemaName -> Text
Event-streaming function that receives the logical queue name and DLQ flag
from each trigger. Queue names ending in _dlq stay unambiguous. A lease-extend
update emits no event.
Source #createEventStreamingTriggersSQL :: SchemaName -> TableName -> Text
Install event-streaming triggers with explicit logical queue metadata.
Source #dropEventStreamingFunctionSQL :: SchemaName -> Text
Drop the schema-wide event-streaming function after its triggers are detached.
Source #dropEventStreamingTriggersSQL :: Text -> Text -> Text
Drop current and legacy event-streaming triggers for a queue and its DLQ. The shared function is dropped separately after every queue is detached.
Notification Channel Helpers
Source #notificationChannelForTable :: TableName -> Text
A table's own job-arrival NOTIFY channel: "email_jobs" -> "email_jobs_created".
Source #eventStreamingChannel :: Text
Channel name used by the event streaming (SSE) system.
Source #pauseNotifyChannel :: SchemaName -> Text -> Text
Per-queue NOTIFY channel for pause/resume changes. Workers LISTEN on the channel for their own queue.
Source #pauseNotifyChannelPrefix :: SchemaName -> Text
Prefix for per-queue pause NOTIFY channels. The full channel name appends
the queue. SQL templates build the channel from queue_name returned by a CTE.
Source #cancelNotifyChannel :: SchemaName -> Text -> Text
Per-queue NOTIFY channel for force-cancel signals. The payload identifies the target worker and job. Only the matching worker reacts.
Source #cancelNotifyChannelPrefix :: SchemaName -> Text
Prefix for per-queue cancel NOTIFY channels. See cancelNotifyChannel.
Source #cronRunNotifyChannel :: SchemaName -> Text
Per-schema NOTIFY channel for manual cron run-now requests.
Trigger / Function Name Helpers
Source #notifyFunctionName :: TableName -> Text
Per-table NOTIFY trigger function name.
Source #notifyTriggerName :: TableName -> Text
Per-table NOTIFY trigger name.
Source #eventStreamingFunctionName :: Text
Shared event streaming trigger function name (one per schema).
Source #eventStreamingTriggerName :: TableName -> Text
Per-table event streaming trigger name.
Source #eventStreamingDLQTriggerName :: TableName -> Text
Per-table DLQ event streaming trigger name.
Source #legacyEventStreamingTriggers :: [(Text, Bool)]
Event-streaming trigger names arbiter generated before the per-queue names, each paired with whether it sits on the DLQ table.
Source #notifyObjectComment :: Text
Ownership marker stamped on every notify function and trigger arbiter installs.
Sweeps match notifyObjectCommentPrefix. A trigger is current when its comment
equals this exact value. Bump the version whenever createNotifyTriggerSQL changes.
Source #notifyObjectCommentPrefix :: Text
The marker prefix identifying a notify object as arbiter's, across versions.
Source #notifyAdoptedObjectComment :: Text
Marker stamped on notify objects installed before arbiter marked them. Sweeps match it. An adopted trigger is rebuilt.
Source #eventStreamingObjectComment :: Text
Ownership marker stamped on every event-streaming function and trigger arbiter
installs. Bump the version whenever createEventStreamingTriggersSQL changes.
Source #eventStreamingObjectCommentPrefix :: Text
The marker prefix identifying an event-streaming object as arbiter's, across versions.
Source #eventStreamingAdoptedObjectComment :: Text
Marker stamped on event-streaming objects installed before arbiter marked them.
See notifyAdoptedObjectComment.
Table Name Helpers
Source #qualifiedTable :: SchemaName -> TableName -> Text
Any schema-qualified table: qualifiedTable "arbiter" "arbiter_workers" -> "arbiter"."arbiter_workers"
Source #jobQueueTable :: SchemaName -> TableName -> Text
Qualified table name: jobQueueTable "arbiter" "email_jobs" -> "arbiter"."email_jobs"
Source #jobQueueDLQTable :: SchemaName -> TableName -> Text
Qualified DLQ table name: jobQueueDLQTable "arbiter" "email_jobs" -> "arbiter"."email_jobs_dlq"
Source #jobQueueArchiveTable :: SchemaName -> TableName -> Text
Qualified archive table name: jobQueueArchiveTable "arbiter" "email_jobs" -> "arbiter"."email_jobs_archive"
Source #jobQueueResultsTable :: Text -> Text -> Text
Qualified results table name: jobQueueResultsTable "arbiter" "email_jobs" -> "arbiter"."email_jobs_results"
Source #jobQueueGroupsTable :: Text -> Text -> Text
Qualified groups table name: jobQueueGroupsTable "arbiter" "email_jobs" -> "arbiter"."email_jobs_groups"
Results Table
Source #createResultsTableSQL :: Text -> Text -> Text
Create a queue's results table, one row per child keyed by (parent_id, child_id).
Its foreign key cascades. Acking the parent clears them.
Maintenance Trigger SQL
Source #maintenanceFunctionNames :: Text -> Text -> (Text, Text, Text)
The qualified baseName_{insert,delete,update} maintenance-function names.