This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

supaqueue-js
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Supaqueue is a job queue for Supabase projects.

Note: This is a work in progress and is not yet ready for production use.

License

MIT

Usage

Supaqueue is a job queue that is backed by your Supabase database. Jobs are enqueued as rows in a supaqueue_jobs table where background workers can pick them up and process them.

A worker is a Supaqueue client does the following:

  1. Dequeues jobs that match the worker's queue
  2. Processes jobs until there are none left
  3. Listens for new jobs using Supabase's Realtime feature

Timeouts, delayed retries, and scale are left to the developer.

Setup

Create a new migration

supabase migration new setup_supaqueue

And add the following SQL from here.

CREATE TABLE IF NOT EXISTS "public"."supaqueue_jobs" (
  "id" bigint NOT NULL,
  "created_at" timestamp with time zone DEFAULT "now"() NOT NULL,
  "queue" "text" NOT NULL,
  "enabled" boolean DEFAULT true NOT NULL,
  "attempts" smallint DEFAULT '0'::smallint NOT NULL,
  "options" "jsonb",
  "payload" "jsonb"
);
ALTER TABLE "public"."supaqueue_jobs" OWNER TO "postgres";
CREATE OR REPLACE FUNCTION "public"."dequeue"("queue_name" character varying) RETURNS SETOF "public"."supaqueue_jobs" LANGUAGE "plpgsql" AS $$ #variable_conflict use_variable
  begin return query
delete from "supaqueue_jobs"
where id = (
    select id
    from "supaqueue_jobs"
    where enabled = true
      and queue = queue_name
    order by created_at asc for
    update skip locked
    limit 1
  )
returning *;
end;
$$;
ALTER FUNCTION "public"."dequeue"("queue_name" character varying) OWNER TO "postgres";
ALTER TABLE "public"."supaqueue_jobs"
ALTER COLUMN "id"
ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME "public"."supaqueue_jobs_id_seq" START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1
  );
CREATE TABLE IF NOT EXISTS "public"."supaqueue_logs" (
  "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL,
  "created_at" timestamp with time zone DEFAULT "now"() NOT NULL,
  "job" "jsonb" NOT NULL,
  "status" character varying NOT NULL
);
ALTER TABLE "public"."supaqueue_logs" OWNER TO "postgres";
ALTER TABLE ONLY "public"."supaqueue_jobs"
ADD CONSTRAINT "supaqueue_jobs_pkey" PRIMARY KEY ("id");
ALTER TABLE ONLY "public"."supaqueue_logs"
ADD CONSTRAINT "supaqueue_logs_pkey" PRIMARY KEY ("id");
ALTER TABLE "public"."supaqueue_jobs" ENABLE ROW LEVEL SECURITY;
ALTER TABLE "public"."supaqueue_logs" ENABLE ROW LEVEL SECURITY;

Then run the migration:

supabase migration up --local

From Supabase studio, head to Database -> Replication. In the row named "supabase_realtime", click the "x table(s)" button under the "Source" column and toggle the "supaqueue_jobs" table to enabled.

Installation

Add Supaqueue to your project:

npm install --save supaqueue-js

Package Sidebar

Install

npm i supaqueue-js

Weekly Downloads

25

Version

1.0.1

License

MIT

Unpacked Size

730 kB

Total Files

12

Last publish

Collaborators

  • davidglivar