Add GoodJob gem.

This is the first step towards replacing DelayedJob with GoodJob. Compared to
DelayedJob:

* GoodJob supports Rails 7 (DelayedJob is currently a blocker for Rails 7
  because it has a version bound on ActiveRecord <6.2).
* GoodJob has a builtin admin dashboard.
* GoodJob supports threaded job workers.
* GoodJob supports scheduled cronjobs.
* GoodJob supports healthchecks for workers.
* GoodJob uses Postgres notifications instead of polling to pick up new
  jobs. This allows jobs to be picked up faster and scales better with
  large numbers of workers.

https://github.com/bensheldon/good_job
This commit is contained in:
evazion
2022-01-01 16:43:13 -06:00
parent 370ed32426
commit c06bfa64f5
4 changed files with 162 additions and 1 deletions

View File

@@ -0,0 +1,36 @@
# frozen_string_literal: true
class CreateGoodJobs < ActiveRecord::Migration[6.1]
def change
enable_extension 'pgcrypto'
create_table :good_jobs, id: :uuid do |t|
t.text :queue_name
t.integer :priority
t.jsonb :serialized_params
t.timestamp :scheduled_at
t.timestamp :performed_at
t.timestamp :finished_at
t.text :error
t.timestamps
t.uuid :active_job_id
t.text :concurrency_key
t.text :cron_key
t.uuid :retried_good_job_id
t.timestamp :cron_at
end
create_table :good_job_processes, id: :uuid do |t|
t.timestamps
t.jsonb :state
end
add_index :good_jobs, :scheduled_at, where: "(finished_at IS NULL)", name: "index_good_jobs_on_scheduled_at"
add_index :good_jobs, [:queue_name, :scheduled_at], where: "(finished_at IS NULL)", name: :index_good_jobs_on_queue_name_and_scheduled_at
add_index :good_jobs, [:active_job_id, :created_at], name: :index_good_jobs_on_active_job_id_and_created_at
add_index :good_jobs, :concurrency_key, where: "(finished_at IS NULL)", name: :index_good_jobs_on_concurrency_key_when_unfinished
add_index :good_jobs, [:cron_key, :created_at], name: :index_good_jobs_on_cron_key_and_created_at
add_index :good_jobs, [:cron_key, :cron_at], name: :index_good_jobs_on_cron_key_and_cron_at, unique: true
end
end

View File

@@ -37,6 +37,20 @@ CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public;
COMMENT ON EXTENSION pg_trgm IS 'text similarity measurement and index searching based on trigrams';
--
-- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;
--
-- Name: EXTENSION pgcrypto; Type: COMMENT; Schema: -; Owner: -
--
COMMENT ON EXTENSION pgcrypto IS 'cryptographic functions';
--
-- Name: pgstattuple; Type: EXTENSION; Schema: -; Owner: -
--
@@ -821,6 +835,41 @@ CREATE SEQUENCE public.forum_topics_id_seq
ALTER SEQUENCE public.forum_topics_id_seq OWNED BY public.forum_topics.id;
--
-- Name: good_job_processes; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.good_job_processes (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
state jsonb
);
--
-- Name: good_jobs; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.good_jobs (
id uuid DEFAULT gen_random_uuid() NOT NULL,
queue_name text,
priority integer,
serialized_params jsonb,
scheduled_at timestamp without time zone,
performed_at timestamp without time zone,
finished_at timestamp without time zone,
error text,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
active_job_id uuid,
concurrency_key text,
cron_key text,
retried_good_job_id uuid,
cron_at timestamp without time zone
);
--
-- Name: note_versions; Type: TABLE; Schema: public; Owner: -
--
@@ -2758,6 +2807,22 @@ ALTER TABLE ONLY public.forum_topics
ADD CONSTRAINT forum_topics_pkey PRIMARY KEY (id);
--
-- Name: good_job_processes good_job_processes_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.good_job_processes
ADD CONSTRAINT good_job_processes_pkey PRIMARY KEY (id);
--
-- Name: good_jobs good_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.good_jobs
ADD CONSTRAINT good_jobs_pkey PRIMARY KEY (id);
--
-- Name: ip_bans ip_bans_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@@ -3605,6 +3670,48 @@ CREATE INDEX index_forum_topics_on_title_tsvector ON public.forum_topics USING g
CREATE INDEX index_forum_topics_on_updated_at ON public.forum_topics USING btree (updated_at);
--
-- Name: index_good_jobs_on_active_job_id_and_created_at; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_good_jobs_on_active_job_id_and_created_at ON public.good_jobs USING btree (active_job_id, created_at);
--
-- Name: index_good_jobs_on_concurrency_key_when_unfinished; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_good_jobs_on_concurrency_key_when_unfinished ON public.good_jobs USING btree (concurrency_key) WHERE (finished_at IS NULL);
--
-- Name: index_good_jobs_on_cron_key_and_created_at; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_good_jobs_on_cron_key_and_created_at ON public.good_jobs USING btree (cron_key, created_at);
--
-- Name: index_good_jobs_on_cron_key_and_cron_at; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX index_good_jobs_on_cron_key_and_cron_at ON public.good_jobs USING btree (cron_key, cron_at);
--
-- Name: index_good_jobs_on_queue_name_and_scheduled_at; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_good_jobs_on_queue_name_and_scheduled_at ON public.good_jobs USING btree (queue_name, scheduled_at) WHERE (finished_at IS NULL);
--
-- Name: index_good_jobs_on_scheduled_at; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_good_jobs_on_scheduled_at ON public.good_jobs USING btree (scheduled_at) WHERE (finished_at IS NULL);
--
-- Name: index_ip_bans_on_category; Type: INDEX; Schema: public; Owner: -
--
@@ -5073,6 +5180,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20211018045429'),
('20211018062916'),
('20211023225730'),
('20211121080239');
('20211121080239'),
('20220101224048');