From 6546c34838d1844aa34bc7aba94b56286c52210a Mon Sep 17 00:00:00 2001 From: Yatish Mehta Date: Fri, 19 Apr 2024 07:23:52 -0700 Subject: [PATCH 1/2] Added support for solid_queue --- Gemfile | 2 + Gemfile.lock | 13 + Procfile | 1 + Procfile.dev | 1 + app/jobs/hello_world_job.rb | 7 + config/application.rb | 3 + config/environments/production.rb | 2 +- config/solid_queue.yml | 18 + ...9_create_solid_queue_tables.solid_queue.rb | 101 +++ ...index_to_blocked_executions.solid_queue.rb | 6 + ...create_recurring_executions.solid_queue.rb | 15 + db/schema.rb | 111 ++- db/structure.sql | 701 +++++++++++++++++- test/jobs/hello_world_job_test.rb | 8 + 14 files changed, 985 insertions(+), 4 deletions(-) create mode 100644 app/jobs/hello_world_job.rb create mode 100644 config/solid_queue.yml create mode 100644 db/migrate/20240419132659_create_solid_queue_tables.solid_queue.rb create mode 100644 db/migrate/20240419132660_add_missing_index_to_blocked_executions.solid_queue.rb create mode 100644 db/migrate/20240419132661_create_recurring_executions.solid_queue.rb create mode 100644 test/jobs/hello_world_job_test.rb diff --git a/Gemfile b/Gemfile index cb9e29e..db9f310 100644 --- a/Gemfile +++ b/Gemfile @@ -31,3 +31,5 @@ group :development do gem "erb_lint", "~> 0.5", require: false gem "bundler-audit", require: false end + +gem "solid_queue", "~> 0.3.0" diff --git a/Gemfile.lock b/Gemfile.lock index 77f1db3..11445ad 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -115,12 +115,17 @@ GEM rubocop smart_properties erubi (1.12.0) + et-orbi (1.2.11) + tzinfo factory_bot (6.4.6) activesupport (>= 5.0.0) factory_bot_rails (6.4.3) factory_bot (~> 6.4) railties (>= 5.0.0) foreman (0.88.1) + fugit (1.9.0) + et-orbi (~> 1, >= 1.2.7) + raabro (~> 1.4) globalid (1.2.1) activesupport (>= 6.1) i18n (1.14.4) @@ -184,6 +189,7 @@ GEM public_suffix (5.0.5) puma (6.4.2) nio4r (~> 2.0) + raabro (1.4.0) racc (1.7.3) rack (3.0.10) rack-proxy (0.7.7) @@ -260,6 +266,12 @@ GEM rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (1.13.0) smart_properties (1.17.0) + solid_queue (0.3.0) + activejob (>= 7.1) + activerecord (>= 7.1) + concurrent-ruby (~> 1.2.2) + fugit (~> 1.9.0) + railties (>= 7.1) stimulus-rails (1.3.3) railties (>= 6.0.0) stringio (3.1.0) @@ -317,6 +329,7 @@ DEPENDENCIES rubocop-minitest rubocop-performance rubocop-rails (>= 2.22.0) + solid_queue (~> 0.3.0) stimulus-rails turbo-rails tzinfo-data diff --git a/Procfile b/Procfile index 90ae0ac..695bf13 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,3 @@ web: bundle exec puma -C config/puma.rb release: bundle exec rake db:migrate +worker: bundle exec rake solid_queue:start diff --git a/Procfile.dev b/Procfile.dev index 1059ed8..fe29ec4 100644 --- a/Procfile.dev +++ b/Procfile.dev @@ -1,2 +1,3 @@ web: env RUBY_DEBUG_OPEN=true bin/rails server vite: bin/vite dev --clobber +worker: bundle exec rake solid_queue:start diff --git a/app/jobs/hello_world_job.rb b/app/jobs/hello_world_job.rb new file mode 100644 index 0000000..8ed48d3 --- /dev/null +++ b/app/jobs/hello_world_job.rb @@ -0,0 +1,7 @@ +class HelloWorldJob < ApplicationJob + def perform(name:) + greeting = "Hello, World!, #{name}" + puts greeting + greeting + end +end diff --git a/config/application.rb b/config/application.rb index c8a2495..4193551 100644 --- a/config/application.rb +++ b/config/application.rb @@ -30,10 +30,13 @@ class Application < Rails::Application # Don't generate system test files. config.generators.system_tests = nil + # Use UUIDs as primary keys for all tables. config.generators do |g| g.orm :active_record, primary_key_type: :uuid end config.active_record.schema_format = :ruby + # Use a real queuing backend for Active Job + config.active_job.queue_adapter = :solid_queue end end diff --git a/config/environments/production.rb b/config/environments/production.rb index 46ff7b0..f87fa21 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -62,7 +62,7 @@ # config.cache_store = :mem_cache_store # Use a real queuing backend for Active Job (and separate queues per environment). - # config.active_job.queue_adapter = :resque + config.active_job.queue_adapter = :solid_queue # config.active_job.queue_name_prefix = "shore_production" config.action_mailer.perform_caching = false diff --git a/config/solid_queue.yml b/config/solid_queue.yml new file mode 100644 index 0000000..bf888ca --- /dev/null +++ b/config/solid_queue.yml @@ -0,0 +1,18 @@ +default: &default + dispatchers: + - polling_interval: 1 + batch_size: 500 + workers: + - queues: "*" + threads: 5 + processes: 1 + polling_interval: 0.1 + +development: + <<: *default + +test: + <<: *default + +production: + <<: *default diff --git a/db/migrate/20240419132659_create_solid_queue_tables.solid_queue.rb b/db/migrate/20240419132659_create_solid_queue_tables.solid_queue.rb new file mode 100644 index 0000000..2591b73 --- /dev/null +++ b/db/migrate/20240419132659_create_solid_queue_tables.solid_queue.rb @@ -0,0 +1,101 @@ +# This migration comes from solid_queue (originally 20231211200639) +class CreateSolidQueueTables < ActiveRecord::Migration[7.0] + def change + create_table :solid_queue_jobs do |t| + t.string :queue_name, null: false + t.string :class_name, null: false, index: true + t.text :arguments + t.integer :priority, default: 0, null: false + t.string :active_job_id, index: true + t.datetime :scheduled_at + t.datetime :finished_at, index: true + t.string :concurrency_key + + t.timestamps + + t.index [:queue_name, :finished_at], name: "index_solid_queue_jobs_for_filtering" + t.index [:scheduled_at, :finished_at], name: "index_solid_queue_jobs_for_alerting" + end + + create_table :solid_queue_scheduled_executions do |t| + t.references :job, index: {unique: true}, null: false + t.string :queue_name, null: false + t.integer :priority, default: 0, null: false + t.datetime :scheduled_at, null: false + + t.datetime :created_at, null: false + + t.index [:scheduled_at, :priority, :job_id], name: "index_solid_queue_dispatch_all" + end + + create_table :solid_queue_ready_executions do |t| + t.references :job, index: {unique: true}, null: false + t.string :queue_name, null: false + t.integer :priority, default: 0, null: false + + t.datetime :created_at, null: false + + t.index [:priority, :job_id], name: "index_solid_queue_poll_all" + t.index [:queue_name, :priority, :job_id], name: "index_solid_queue_poll_by_queue" + end + + create_table :solid_queue_claimed_executions do |t| + t.references :job, index: {unique: true}, null: false + t.bigint :process_id + t.datetime :created_at, null: false + + t.index [:process_id, :job_id] + end + + create_table :solid_queue_blocked_executions do |t| + t.references :job, index: {unique: true}, null: false + t.string :queue_name, null: false + t.integer :priority, default: 0, null: false + t.string :concurrency_key, null: false + t.datetime :expires_at, null: false + + t.datetime :created_at, null: false + + t.index [:expires_at, :concurrency_key], name: "index_solid_queue_blocked_executions_for_maintenance" + end + + create_table :solid_queue_failed_executions do |t| + t.references :job, index: {unique: true}, null: false + t.text :error + t.datetime :created_at, null: false + end + + create_table :solid_queue_pauses do |t| + t.string :queue_name, null: false, index: {unique: true} + t.datetime :created_at, null: false + end + + create_table :solid_queue_processes do |t| + t.string :kind, null: false + t.datetime :last_heartbeat_at, null: false, index: true + t.bigint :supervisor_id, index: true + + t.integer :pid, null: false + t.string :hostname + t.text :metadata + + t.datetime :created_at, null: false + end + + create_table :solid_queue_semaphores do |t| + t.string :key, null: false, index: {unique: true} + t.integer :value, default: 1, null: false + t.datetime :expires_at, null: false, index: true + + t.timestamps + + t.index [:key, :value], name: "index_solid_queue_semaphores_on_key_and_value" + end + + add_foreign_key :solid_queue_blocked_executions, :solid_queue_jobs, column: :job_id, on_delete: :cascade + add_foreign_key :solid_queue_claimed_executions, :solid_queue_jobs, column: :job_id, on_delete: :cascade + add_foreign_key :solid_queue_failed_executions, :solid_queue_jobs, column: :job_id, on_delete: :cascade + add_foreign_key :solid_queue_ready_executions, :solid_queue_jobs, column: :job_id, on_delete: :cascade + add_foreign_key :solid_queue_scheduled_executions, :solid_queue_jobs, column: :job_id, on_delete: :cascade + end +end diff --git a/db/migrate/20240419132660_add_missing_index_to_blocked_executions.solid_queue.rb b/db/migrate/20240419132660_add_missing_index_to_blocked_executions.solid_queue.rb new file mode 100644 index 0000000..2d96b10 --- /dev/null +++ b/db/migrate/20240419132660_add_missing_index_to_blocked_executions.solid_queue.rb @@ -0,0 +1,6 @@ +# This migration comes from solid_queue (originally 20240110143450) +class AddMissingIndexToBlockedExecutions < ActiveRecord::Migration[7.1] + def change + add_index :solid_queue_blocked_executions, [ :concurrency_key, :priority, :job_id ], name: "index_solid_queue_blocked_executions_for_release" + end +end diff --git a/db/migrate/20240419132661_create_recurring_executions.solid_queue.rb b/db/migrate/20240419132661_create_recurring_executions.solid_queue.rb new file mode 100644 index 0000000..7f441b2 --- /dev/null +++ b/db/migrate/20240419132661_create_recurring_executions.solid_queue.rb @@ -0,0 +1,15 @@ +# This migration comes from solid_queue (originally 20240218110712) +class CreateRecurringExecutions < ActiveRecord::Migration[7.1] + def change + create_table :solid_queue_recurring_executions do |t| + t.references :job, index: {unique: true}, null: false + t.string :task_key, null: false + t.datetime :run_at, null: false + t.datetime :created_at, null: false + + t.index [:task_key, :run_at], unique: true + end + + add_foreign_key :solid_queue_recurring_executions, :solid_queue_jobs, column: :job_id, on_delete: :cascade + end +end diff --git a/db/schema.rb b/db/schema.rb index e3592b4..879fc4c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,9 +10,118 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_04_19_061730) do +ActiveRecord::Schema[7.1].define(version: 2024_04_19_132661) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" + create_table "solid_queue_blocked_executions", force: :cascade do |t| + t.bigint "job_id", null: false + t.string "queue_name", null: false + t.integer "priority", default: 0, null: false + t.string "concurrency_key", null: false + t.datetime "expires_at", null: false + t.datetime "created_at", null: false + t.index ["concurrency_key", "priority", "job_id"], name: "index_solid_queue_blocked_executions_for_release" + t.index ["expires_at", "concurrency_key"], name: "index_solid_queue_blocked_executions_for_maintenance" + t.index ["job_id"], name: "index_solid_queue_blocked_executions_on_job_id", unique: true + end + + create_table "solid_queue_claimed_executions", force: :cascade do |t| + t.bigint "job_id", null: false + t.bigint "process_id" + t.datetime "created_at", null: false + t.index ["job_id"], name: "index_solid_queue_claimed_executions_on_job_id", unique: true + t.index ["process_id", "job_id"], name: "index_solid_queue_claimed_executions_on_process_id_and_job_id" + end + + create_table "solid_queue_failed_executions", force: :cascade do |t| + t.bigint "job_id", null: false + t.text "error" + t.datetime "created_at", null: false + t.index ["job_id"], name: "index_solid_queue_failed_executions_on_job_id", unique: true + end + + create_table "solid_queue_jobs", force: :cascade do |t| + t.string "queue_name", null: false + t.string "class_name", null: false + t.text "arguments" + t.integer "priority", default: 0, null: false + t.string "active_job_id" + t.datetime "scheduled_at" + t.datetime "finished_at" + t.string "concurrency_key" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["active_job_id"], name: "index_solid_queue_jobs_on_active_job_id" + t.index ["class_name"], name: "index_solid_queue_jobs_on_class_name" + t.index ["finished_at"], name: "index_solid_queue_jobs_on_finished_at" + t.index ["queue_name", "finished_at"], name: "index_solid_queue_jobs_for_filtering" + t.index ["scheduled_at", "finished_at"], name: "index_solid_queue_jobs_for_alerting" + end + + create_table "solid_queue_pauses", force: :cascade do |t| + t.string "queue_name", null: false + t.datetime "created_at", null: false + t.index ["queue_name"], name: "index_solid_queue_pauses_on_queue_name", unique: true + end + + create_table "solid_queue_processes", force: :cascade do |t| + t.string "kind", null: false + t.datetime "last_heartbeat_at", null: false + t.bigint "supervisor_id" + t.integer "pid", null: false + t.string "hostname" + t.text "metadata" + t.datetime "created_at", null: false + t.index ["last_heartbeat_at"], name: "index_solid_queue_processes_on_last_heartbeat_at" + t.index ["supervisor_id"], name: "index_solid_queue_processes_on_supervisor_id" + end + + create_table "solid_queue_ready_executions", force: :cascade do |t| + t.bigint "job_id", null: false + t.string "queue_name", null: false + t.integer "priority", default: 0, null: false + t.datetime "created_at", null: false + t.index ["job_id"], name: "index_solid_queue_ready_executions_on_job_id", unique: true + t.index ["priority", "job_id"], name: "index_solid_queue_poll_all" + t.index ["queue_name", "priority", "job_id"], name: "index_solid_queue_poll_by_queue" + end + + create_table "solid_queue_recurring_executions", force: :cascade do |t| + t.bigint "job_id", null: false + t.string "task_key", null: false + t.datetime "run_at", null: false + t.datetime "created_at", null: false + t.index ["job_id"], name: "index_solid_queue_recurring_executions_on_job_id", unique: true + t.index ["task_key", "run_at"], name: "index_solid_queue_recurring_executions_on_task_key_and_run_at", unique: true + end + + create_table "solid_queue_scheduled_executions", force: :cascade do |t| + t.bigint "job_id", null: false + t.string "queue_name", null: false + t.integer "priority", default: 0, null: false + t.datetime "scheduled_at", null: false + t.datetime "created_at", null: false + t.index ["job_id"], name: "index_solid_queue_scheduled_executions_on_job_id", unique: true + t.index ["scheduled_at", "priority", "job_id"], name: "index_solid_queue_dispatch_all" + end + + create_table "solid_queue_semaphores", force: :cascade do |t| + t.string "key", null: false + t.integer "value", default: 1, null: false + t.datetime "expires_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["expires_at"], name: "index_solid_queue_semaphores_on_expires_at" + t.index ["key", "value"], name: "index_solid_queue_semaphores_on_key_and_value" + t.index ["key"], name: "index_solid_queue_semaphores_on_key", unique: true + end + + add_foreign_key "solid_queue_blocked_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_claimed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_failed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_ready_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_recurring_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_scheduled_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade end diff --git a/db/structure.sql b/db/structure.sql index 4679ec4..2880bdf 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -48,6 +48,405 @@ CREATE TABLE public.schema_migrations ( ); +-- +-- Name: solid_queue_blocked_executions; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.solid_queue_blocked_executions ( + id bigint NOT NULL, + job_id bigint NOT NULL, + queue_name character varying NOT NULL, + priority integer DEFAULT 0 NOT NULL, + concurrency_key character varying NOT NULL, + expires_at timestamp(6) without time zone NOT NULL, + created_at timestamp(6) without time zone NOT NULL +); + + +-- +-- Name: solid_queue_blocked_executions_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.solid_queue_blocked_executions_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: solid_queue_blocked_executions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.solid_queue_blocked_executions_id_seq OWNED BY public.solid_queue_blocked_executions.id; + + +-- +-- Name: solid_queue_claimed_executions; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.solid_queue_claimed_executions ( + id bigint NOT NULL, + job_id bigint NOT NULL, + process_id bigint, + created_at timestamp(6) without time zone NOT NULL +); + + +-- +-- Name: solid_queue_claimed_executions_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.solid_queue_claimed_executions_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: solid_queue_claimed_executions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.solid_queue_claimed_executions_id_seq OWNED BY public.solid_queue_claimed_executions.id; + + +-- +-- Name: solid_queue_failed_executions; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.solid_queue_failed_executions ( + id bigint NOT NULL, + job_id bigint NOT NULL, + error text, + created_at timestamp(6) without time zone NOT NULL +); + + +-- +-- Name: solid_queue_failed_executions_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.solid_queue_failed_executions_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: solid_queue_failed_executions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.solid_queue_failed_executions_id_seq OWNED BY public.solid_queue_failed_executions.id; + + +-- +-- Name: solid_queue_jobs; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.solid_queue_jobs ( + id bigint NOT NULL, + queue_name character varying NOT NULL, + class_name character varying NOT NULL, + arguments text, + priority integer DEFAULT 0 NOT NULL, + active_job_id character varying, + scheduled_at timestamp(6) without time zone, + finished_at timestamp(6) without time zone, + concurrency_key character varying, + created_at timestamp(6) without time zone NOT NULL, + updated_at timestamp(6) without time zone NOT NULL +); + + +-- +-- Name: solid_queue_jobs_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.solid_queue_jobs_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: solid_queue_jobs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.solid_queue_jobs_id_seq OWNED BY public.solid_queue_jobs.id; + + +-- +-- Name: solid_queue_pauses; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.solid_queue_pauses ( + id bigint NOT NULL, + queue_name character varying NOT NULL, + created_at timestamp(6) without time zone NOT NULL +); + + +-- +-- Name: solid_queue_pauses_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.solid_queue_pauses_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: solid_queue_pauses_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.solid_queue_pauses_id_seq OWNED BY public.solid_queue_pauses.id; + + +-- +-- Name: solid_queue_processes; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.solid_queue_processes ( + id bigint NOT NULL, + kind character varying NOT NULL, + last_heartbeat_at timestamp(6) without time zone NOT NULL, + supervisor_id bigint, + pid integer NOT NULL, + hostname character varying, + metadata text, + created_at timestamp(6) without time zone NOT NULL +); + + +-- +-- Name: solid_queue_processes_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.solid_queue_processes_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: solid_queue_processes_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.solid_queue_processes_id_seq OWNED BY public.solid_queue_processes.id; + + +-- +-- Name: solid_queue_ready_executions; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.solid_queue_ready_executions ( + id bigint NOT NULL, + job_id bigint NOT NULL, + queue_name character varying NOT NULL, + priority integer DEFAULT 0 NOT NULL, + created_at timestamp(6) without time zone NOT NULL +); + + +-- +-- Name: solid_queue_ready_executions_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.solid_queue_ready_executions_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: solid_queue_ready_executions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.solid_queue_ready_executions_id_seq OWNED BY public.solid_queue_ready_executions.id; + + +-- +-- Name: solid_queue_recurring_executions; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.solid_queue_recurring_executions ( + id bigint NOT NULL, + job_id bigint NOT NULL, + task_key character varying NOT NULL, + run_at timestamp(6) without time zone NOT NULL, + created_at timestamp(6) without time zone NOT NULL +); + + +-- +-- Name: solid_queue_recurring_executions_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.solid_queue_recurring_executions_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: solid_queue_recurring_executions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.solid_queue_recurring_executions_id_seq OWNED BY public.solid_queue_recurring_executions.id; + + +-- +-- Name: solid_queue_scheduled_executions; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.solid_queue_scheduled_executions ( + id bigint NOT NULL, + job_id bigint NOT NULL, + queue_name character varying NOT NULL, + priority integer DEFAULT 0 NOT NULL, + scheduled_at timestamp(6) without time zone NOT NULL, + created_at timestamp(6) without time zone NOT NULL +); + + +-- +-- Name: solid_queue_scheduled_executions_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.solid_queue_scheduled_executions_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: solid_queue_scheduled_executions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.solid_queue_scheduled_executions_id_seq OWNED BY public.solid_queue_scheduled_executions.id; + + +-- +-- Name: solid_queue_semaphores; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.solid_queue_semaphores ( + id bigint NOT NULL, + key character varying NOT NULL, + value integer DEFAULT 1 NOT NULL, + expires_at timestamp(6) without time zone NOT NULL, + created_at timestamp(6) without time zone NOT NULL, + updated_at timestamp(6) without time zone NOT NULL +); + + +-- +-- Name: solid_queue_semaphores_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.solid_queue_semaphores_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: solid_queue_semaphores_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.solid_queue_semaphores_id_seq OWNED BY public.solid_queue_semaphores.id; + + +-- +-- Name: solid_queue_blocked_executions id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_blocked_executions ALTER COLUMN id SET DEFAULT nextval('public.solid_queue_blocked_executions_id_seq'::regclass); + + +-- +-- Name: solid_queue_claimed_executions id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_claimed_executions ALTER COLUMN id SET DEFAULT nextval('public.solid_queue_claimed_executions_id_seq'::regclass); + + +-- +-- Name: solid_queue_failed_executions id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_failed_executions ALTER COLUMN id SET DEFAULT nextval('public.solid_queue_failed_executions_id_seq'::regclass); + + +-- +-- Name: solid_queue_jobs id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_jobs ALTER COLUMN id SET DEFAULT nextval('public.solid_queue_jobs_id_seq'::regclass); + + +-- +-- Name: solid_queue_pauses id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_pauses ALTER COLUMN id SET DEFAULT nextval('public.solid_queue_pauses_id_seq'::regclass); + + +-- +-- Name: solid_queue_processes id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_processes ALTER COLUMN id SET DEFAULT nextval('public.solid_queue_processes_id_seq'::regclass); + + +-- +-- Name: solid_queue_ready_executions id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_ready_executions ALTER COLUMN id SET DEFAULT nextval('public.solid_queue_ready_executions_id_seq'::regclass); + + +-- +-- Name: solid_queue_recurring_executions id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_recurring_executions ALTER COLUMN id SET DEFAULT nextval('public.solid_queue_recurring_executions_id_seq'::regclass); + + +-- +-- Name: solid_queue_scheduled_executions id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_scheduled_executions ALTER COLUMN id SET DEFAULT nextval('public.solid_queue_scheduled_executions_id_seq'::regclass); + + +-- +-- Name: solid_queue_semaphores id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_semaphores ALTER COLUMN id SET DEFAULT nextval('public.solid_queue_semaphores_id_seq'::regclass); + + -- -- Name: ar_internal_metadata ar_internal_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -64,6 +463,302 @@ ALTER TABLE ONLY public.schema_migrations ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version); +-- +-- Name: solid_queue_blocked_executions solid_queue_blocked_executions_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_blocked_executions + ADD CONSTRAINT solid_queue_blocked_executions_pkey PRIMARY KEY (id); + + +-- +-- Name: solid_queue_claimed_executions solid_queue_claimed_executions_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_claimed_executions + ADD CONSTRAINT solid_queue_claimed_executions_pkey PRIMARY KEY (id); + + +-- +-- Name: solid_queue_failed_executions solid_queue_failed_executions_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_failed_executions + ADD CONSTRAINT solid_queue_failed_executions_pkey PRIMARY KEY (id); + + +-- +-- Name: solid_queue_jobs solid_queue_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_jobs + ADD CONSTRAINT solid_queue_jobs_pkey PRIMARY KEY (id); + + +-- +-- Name: solid_queue_pauses solid_queue_pauses_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_pauses + ADD CONSTRAINT solid_queue_pauses_pkey PRIMARY KEY (id); + + +-- +-- Name: solid_queue_processes solid_queue_processes_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_processes + ADD CONSTRAINT solid_queue_processes_pkey PRIMARY KEY (id); + + +-- +-- Name: solid_queue_ready_executions solid_queue_ready_executions_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_ready_executions + ADD CONSTRAINT solid_queue_ready_executions_pkey PRIMARY KEY (id); + + +-- +-- Name: solid_queue_recurring_executions solid_queue_recurring_executions_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_recurring_executions + ADD CONSTRAINT solid_queue_recurring_executions_pkey PRIMARY KEY (id); + + +-- +-- Name: solid_queue_scheduled_executions solid_queue_scheduled_executions_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_scheduled_executions + ADD CONSTRAINT solid_queue_scheduled_executions_pkey PRIMARY KEY (id); + + +-- +-- Name: solid_queue_semaphores solid_queue_semaphores_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_semaphores + ADD CONSTRAINT solid_queue_semaphores_pkey PRIMARY KEY (id); + + +-- +-- Name: index_solid_queue_blocked_executions_for_maintenance; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_solid_queue_blocked_executions_for_maintenance ON public.solid_queue_blocked_executions USING btree (expires_at, concurrency_key); + + +-- +-- Name: index_solid_queue_blocked_executions_for_release; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_solid_queue_blocked_executions_for_release ON public.solid_queue_blocked_executions USING btree (concurrency_key, priority, job_id); + + +-- +-- Name: index_solid_queue_blocked_executions_on_job_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_solid_queue_blocked_executions_on_job_id ON public.solid_queue_blocked_executions USING btree (job_id); + + +-- +-- Name: index_solid_queue_claimed_executions_on_job_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_solid_queue_claimed_executions_on_job_id ON public.solid_queue_claimed_executions USING btree (job_id); + + +-- +-- Name: index_solid_queue_claimed_executions_on_process_id_and_job_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_solid_queue_claimed_executions_on_process_id_and_job_id ON public.solid_queue_claimed_executions USING btree (process_id, job_id); + + +-- +-- Name: index_solid_queue_dispatch_all; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_solid_queue_dispatch_all ON public.solid_queue_scheduled_executions USING btree (scheduled_at, priority, job_id); + + +-- +-- Name: index_solid_queue_failed_executions_on_job_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_solid_queue_failed_executions_on_job_id ON public.solid_queue_failed_executions USING btree (job_id); + + +-- +-- Name: index_solid_queue_jobs_for_alerting; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_solid_queue_jobs_for_alerting ON public.solid_queue_jobs USING btree (scheduled_at, finished_at); + + +-- +-- Name: index_solid_queue_jobs_for_filtering; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_solid_queue_jobs_for_filtering ON public.solid_queue_jobs USING btree (queue_name, finished_at); + + +-- +-- Name: index_solid_queue_jobs_on_active_job_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_solid_queue_jobs_on_active_job_id ON public.solid_queue_jobs USING btree (active_job_id); + + +-- +-- Name: index_solid_queue_jobs_on_class_name; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_solid_queue_jobs_on_class_name ON public.solid_queue_jobs USING btree (class_name); + + +-- +-- Name: index_solid_queue_jobs_on_finished_at; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_solid_queue_jobs_on_finished_at ON public.solid_queue_jobs USING btree (finished_at); + + +-- +-- Name: index_solid_queue_pauses_on_queue_name; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_solid_queue_pauses_on_queue_name ON public.solid_queue_pauses USING btree (queue_name); + + +-- +-- Name: index_solid_queue_poll_all; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_solid_queue_poll_all ON public.solid_queue_ready_executions USING btree (priority, job_id); + + +-- +-- Name: index_solid_queue_poll_by_queue; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_solid_queue_poll_by_queue ON public.solid_queue_ready_executions USING btree (queue_name, priority, job_id); + + +-- +-- Name: index_solid_queue_processes_on_last_heartbeat_at; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_solid_queue_processes_on_last_heartbeat_at ON public.solid_queue_processes USING btree (last_heartbeat_at); + + +-- +-- Name: index_solid_queue_processes_on_supervisor_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_solid_queue_processes_on_supervisor_id ON public.solid_queue_processes USING btree (supervisor_id); + + +-- +-- Name: index_solid_queue_ready_executions_on_job_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_solid_queue_ready_executions_on_job_id ON public.solid_queue_ready_executions USING btree (job_id); + + +-- +-- Name: index_solid_queue_recurring_executions_on_job_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_solid_queue_recurring_executions_on_job_id ON public.solid_queue_recurring_executions USING btree (job_id); + + +-- +-- Name: index_solid_queue_recurring_executions_on_task_key_and_run_at; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_solid_queue_recurring_executions_on_task_key_and_run_at ON public.solid_queue_recurring_executions USING btree (task_key, run_at); + + +-- +-- Name: index_solid_queue_scheduled_executions_on_job_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_solid_queue_scheduled_executions_on_job_id ON public.solid_queue_scheduled_executions USING btree (job_id); + + +-- +-- Name: index_solid_queue_semaphores_on_expires_at; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_solid_queue_semaphores_on_expires_at ON public.solid_queue_semaphores USING btree (expires_at); + + +-- +-- Name: index_solid_queue_semaphores_on_key; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_solid_queue_semaphores_on_key ON public.solid_queue_semaphores USING btree (key); + + +-- +-- Name: index_solid_queue_semaphores_on_key_and_value; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_solid_queue_semaphores_on_key_and_value ON public.solid_queue_semaphores USING btree (key, value); + + +-- +-- Name: solid_queue_recurring_executions fk_rails_318a5533ed; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_recurring_executions + ADD CONSTRAINT fk_rails_318a5533ed FOREIGN KEY (job_id) REFERENCES public.solid_queue_jobs(id) ON DELETE CASCADE; + + +-- +-- Name: solid_queue_failed_executions fk_rails_39bbc7a631; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_failed_executions + ADD CONSTRAINT fk_rails_39bbc7a631 FOREIGN KEY (job_id) REFERENCES public.solid_queue_jobs(id) ON DELETE CASCADE; + + +-- +-- Name: solid_queue_blocked_executions fk_rails_4cd34e2228; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_blocked_executions + ADD CONSTRAINT fk_rails_4cd34e2228 FOREIGN KEY (job_id) REFERENCES public.solid_queue_jobs(id) ON DELETE CASCADE; + + +-- +-- Name: solid_queue_ready_executions fk_rails_81fcbd66af; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_ready_executions + ADD CONSTRAINT fk_rails_81fcbd66af FOREIGN KEY (job_id) REFERENCES public.solid_queue_jobs(id) ON DELETE CASCADE; + + +-- +-- Name: solid_queue_claimed_executions fk_rails_9cfe4d4944; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_claimed_executions + ADD CONSTRAINT fk_rails_9cfe4d4944 FOREIGN KEY (job_id) REFERENCES public.solid_queue_jobs(id) ON DELETE CASCADE; + + +-- +-- Name: solid_queue_scheduled_executions fk_rails_c4316f352d; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.solid_queue_scheduled_executions + ADD CONSTRAINT fk_rails_c4316f352d FOREIGN KEY (job_id) REFERENCES public.solid_queue_jobs(id) ON DELETE CASCADE; + + -- -- PostgreSQL database dump complete -- @@ -71,6 +766,8 @@ ALTER TABLE ONLY public.schema_migrations SET search_path TO "$user", public; INSERT INTO "schema_migrations" (version) VALUES -('20240419061730'), -('0'); +('20240419132661'), +('20240419132660'), +('20240419132659'), +('20240419061730'); diff --git a/test/jobs/hello_world_job_test.rb b/test/jobs/hello_world_job_test.rb new file mode 100644 index 0000000..35bc689 --- /dev/null +++ b/test/jobs/hello_world_job_test.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class HelloWorldJobTest < ActiveJob::TestCase + test "greets hello world" do + result = HelloWorldJob.perform_now(name: "Alice") + assert_equal "Hello, World!, Alice", result + end +end From 8cbdd8e4cc65284f4d6eae1e6c00dac5b7f002a7 Mon Sep 17 00:00:00 2001 From: Yatish Mehta Date: Fri, 19 Apr 2024 07:25:40 -0700 Subject: [PATCH 2/2] Fixed rubocop --- ...32660_add_missing_index_to_blocked_executions.solid_queue.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20240419132660_add_missing_index_to_blocked_executions.solid_queue.rb b/db/migrate/20240419132660_add_missing_index_to_blocked_executions.solid_queue.rb index 2d96b10..53e74dc 100644 --- a/db/migrate/20240419132660_add_missing_index_to_blocked_executions.solid_queue.rb +++ b/db/migrate/20240419132660_add_missing_index_to_blocked_executions.solid_queue.rb @@ -1,6 +1,6 @@ # This migration comes from solid_queue (originally 20240110143450) class AddMissingIndexToBlockedExecutions < ActiveRecord::Migration[7.1] def change - add_index :solid_queue_blocked_executions, [ :concurrency_key, :priority, :job_id ], name: "index_solid_queue_blocked_executions_for_release" + add_index :solid_queue_blocked_executions, [:concurrency_key, :priority, :job_id], name: "index_solid_queue_blocked_executions_for_release" end end