mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-01-06 08:49:53 -06:00
feat: postgres-backed message queue (#1119)
This commit is contained in:
@@ -3,4 +3,65 @@ ALTER TYPE "ConcurrencyLimitStrategy" ADD VALUE 'CANCEL_NEWEST';
|
||||
-- Add value to enum type: "WorkflowRunStatus"
|
||||
ALTER TYPE "WorkflowRunStatus" ADD VALUE 'CANCELLING';
|
||||
-- Add value to enum type: "WorkflowRunStatus"
|
||||
ALTER TYPE "WorkflowRunStatus" ADD VALUE 'CANCELLED';
|
||||
ALTER TYPE "WorkflowRunStatus" ADD VALUE 'CANCELLED';
|
||||
-- Create enum type "MessageQueueItemStatus"
|
||||
CREATE TYPE "MessageQueueItemStatus" AS ENUM('PENDING', 'ASSIGNED');
|
||||
|
||||
-- Create "MessageQueue" table
|
||||
CREATE TABLE
|
||||
"MessageQueue" (
|
||||
"name" text NOT NULL,
|
||||
"lastActive" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
|
||||
"durable" boolean NOT NULL DEFAULT true,
|
||||
"autoDeleted" boolean NOT NULL DEFAULT false,
|
||||
"exclusive" boolean NOT NULL DEFAULT false,
|
||||
"exclusiveConsumerId" uuid NULL,
|
||||
PRIMARY KEY ("name")
|
||||
);
|
||||
|
||||
-- Create "MessageQueueItem" table
|
||||
CREATE TABLE
|
||||
"MessageQueueItem" (
|
||||
"id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY,
|
||||
"payload" jsonb NOT NULL,
|
||||
"readAfter" timestamp(3) NULL,
|
||||
"expiresAt" timestamp(3) NULL,
|
||||
"queueId" text,
|
||||
"status" "MessageQueueItemStatus" NOT NULL DEFAULT 'PENDING',
|
||||
PRIMARY KEY ("id"),
|
||||
CONSTRAINT "MessageQueueItem_queueId_fkey" FOREIGN KEY ("queueId") REFERENCES "MessageQueue" ("name") ON UPDATE NO ACTION ON DELETE SET NULL
|
||||
);
|
||||
|
||||
-- Create index "MessageQueueItem_queueId_expiresAt_readAfter_status_id_idx" to table: "MessageQueueItem"
|
||||
CREATE INDEX "MessageQueueItem_queueId_expiresAt_readAfter_status_id_idx" ON "MessageQueueItem" (
|
||||
"expiresAt",
|
||||
"queueId",
|
||||
"readAfter",
|
||||
"status",
|
||||
"id"
|
||||
);
|
||||
|
||||
-- Function to publish NOTIFY message on insert into MessageQueueItem
|
||||
CREATE
|
||||
OR REPLACE FUNCTION notify_message_queue_item () RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
PERFORM pg_notify(
|
||||
NEW."queueId"::TEXT,
|
||||
NEW."id"::TEXT
|
||||
);
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
-- Trigger to invoke the notify function after insert
|
||||
CREATE TRIGGER trigger_notify_message_queue_item
|
||||
AFTER INSERT ON "MessageQueueItem" FOR EACH ROW
|
||||
EXECUTE FUNCTION notify_message_queue_item ();
|
||||
|
||||
-- Update the existing function to prevent internal name or slug to be a no-op
|
||||
CREATE
|
||||
OR REPLACE FUNCTION prevent_internal_name_or_slug () RETURNS trigger AS $$
|
||||
BEGIN
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
@@ -1,4 +1,4 @@
|
||||
h1:kdjvzXzgnUl33aT2nO6fMW3ZNMIfO5zf4/dxS6cp1sQ=
|
||||
h1:1Az5U4thlaLVJj4xo1BN9WtRVjaMytq41j5vy94dyuE=
|
||||
20240115180414_init.sql h1:Ef3ZyjAHkmJPdGF/dEWCahbwgcg6uGJKnDxW2JCRi2k=
|
||||
20240122014727_v0_6_0.sql h1:o/LdlteAeFgoHJ3e/M4Xnghqt9826IE/Y/h0q95Acuo=
|
||||
20240126235456_v0_7_0.sql h1:KiVzt/hXgQ6esbdC6OMJOOWuYEXmy1yeCpmsVAHTFKs=
|
||||
@@ -79,4 +79,4 @@ h1:kdjvzXzgnUl33aT2nO6fMW3ZNMIfO5zf4/dxS6cp1sQ=
|
||||
20241204191714_v0.52.5.sql h1:6oJgHJynK+YtwQoD/VnqiCMda409K96A4Oq2l8h3dQ0=
|
||||
20241206231312_v0.52.12.sql h1:6L/zXbiVC24nqSzJzqItPFKCA3HPyMk0T5pBPnmXQgg=
|
||||
20241216175807_v0.52.13.sql h1:rMwIaYvy3WX/F7/go1J3vI+WNYnABpASv0ATPJt1pE8=
|
||||
20241217152316_v0.53.0.sql h1:sXmW2KigCn3hGZxCJhSPk6GjO3b+ppDgfMiLz5Xv3RQ=
|
||||
20241217152316_v0.53.0.sql h1:iFz58oq8r6rDcM3HcainoblLXwOpCgayvNdQwC77Sho=
|
||||
|
||||
@@ -1077,6 +1077,38 @@ CREATE TABLE
|
||||
CREATE TABLE
|
||||
"_WorkflowToWorkflowTag" ("A" UUID NOT NULL, "B" UUID NOT NULL);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "MessageQueue" (
|
||||
"name" TEXT NOT NULL,
|
||||
"lastActive" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
|
||||
"durable" BOOLEAN NOT NULL DEFAULT true,
|
||||
"autoDeleted" BOOLEAN NOT NULL DEFAULT false,
|
||||
"exclusive" BOOLEAN NOT NULL DEFAULT false,
|
||||
"exclusiveConsumerId" UUID,
|
||||
CONSTRAINT "MessageQueue_pkey" PRIMARY KEY ("name")
|
||||
);
|
||||
|
||||
-- CreateEnum
|
||||
CREATE TYPE "MessageQueueItemStatus" AS ENUM (
|
||||
'PENDING',
|
||||
'ASSIGNED'
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "MessageQueueItem" (
|
||||
"id" bigint GENERATED ALWAYS AS IDENTITY,
|
||||
"payload" JSONB NOT NULL,
|
||||
"readAfter" TIMESTAMP(3),
|
||||
"expiresAt" TIMESTAMP(3),
|
||||
"queueId" TEXT,
|
||||
"status" "MessageQueueItemStatus" NOT NULL DEFAULT 'PENDING',
|
||||
CONSTRAINT "MessageQueueItem_pkey" PRIMARY KEY ("id"),
|
||||
CONSTRAINT "MessageQueueItem_queueId_fkey" FOREIGN KEY ("queueId") REFERENCES "MessageQueue" ("name") ON DELETE SET NULL
|
||||
);
|
||||
|
||||
-- Create an index for message queue item
|
||||
CREATE INDEX "MessageQueueItem_queueId_expiresAt_readAfter_status_id_idx" ON "MessageQueueItem" ("expiresAt", "queueId", "readAfter", "status", "id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "APIToken_id_key" ON "APIToken" ("id" ASC);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user