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:
1
Gemfile
1
Gemfile
@@ -56,6 +56,7 @@ gem "pry-byebug"
|
||||
gem "pry-rails"
|
||||
gem "ffi"
|
||||
gem "rbtrace"
|
||||
gem "good_job"
|
||||
|
||||
group :development do
|
||||
gem 'rubocop', require: false
|
||||
|
||||
16
Gemfile.lock
16
Gemfile.lock
@@ -165,6 +165,8 @@ GEM
|
||||
e2mmap (0.1.0)
|
||||
ed25519 (1.2.4)
|
||||
erubi (1.10.0)
|
||||
et-orbi (1.2.6)
|
||||
tzinfo
|
||||
factory_bot (6.2.0)
|
||||
activesupport (>= 5.0.0)
|
||||
faraday (1.8.0)
|
||||
@@ -192,10 +194,22 @@ GEM
|
||||
ffi (>= 1.0.0)
|
||||
rake
|
||||
flamegraph (0.9.5)
|
||||
fugit (1.5.2)
|
||||
et-orbi (~> 1.1, >= 1.1.8)
|
||||
raabro (~> 1.4)
|
||||
get_process_mem (0.2.7)
|
||||
ffi (~> 1.0)
|
||||
globalid (1.0.0)
|
||||
activesupport (>= 5.0)
|
||||
good_job (2.8.0)
|
||||
activejob (>= 5.2.0)
|
||||
activerecord (>= 5.2.0)
|
||||
concurrent-ruby (>= 1.0.2)
|
||||
fugit (>= 1.1)
|
||||
railties (>= 5.2.0)
|
||||
thor (>= 0.14.1)
|
||||
webrick (>= 1.3)
|
||||
zeitwerk (>= 2.0)
|
||||
google-apis-bigquery_v2 (0.22.0)
|
||||
google-apis-core (>= 0.4, < 2.a)
|
||||
google-apis-core (0.4.1)
|
||||
@@ -332,6 +346,7 @@ GEM
|
||||
puma (>= 2.7)
|
||||
pundit (2.1.1)
|
||||
activesupport (>= 3.0.0)
|
||||
raabro (1.4.0)
|
||||
racc (1.6.0)
|
||||
rack (2.2.3)
|
||||
rack-contrib (2.3.0)
|
||||
@@ -533,6 +548,7 @@ DEPENDENCIES
|
||||
ffaker
|
||||
ffi
|
||||
flamegraph
|
||||
good_job
|
||||
google-cloud-bigquery
|
||||
google-cloud-storage
|
||||
hsluv
|
||||
|
||||
36
db/migrate/20220101224048_create_good_jobs.rb
Normal file
36
db/migrate/20220101224048_create_good_jobs.rb
Normal 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
|
||||
110
db/structure.sql
110
db/structure.sql
@@ -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');
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user