From d558584640ea23b0eb456d63852e29fd7fdc7ac1 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Mon, 8 Jul 2024 14:13:59 -0300 Subject: [PATCH] fix: lock GoodJob dependency to < 4.0 (#211) GoodJob v4 was recently released, but that has some breaking changes that don't work well with Judoscale yet. Before adding full support to the new version, we're doing a patch release to lock it to version < 4, so that people trying to install both don't run into problems using GoodJob v4 and Judoscale. https://island94.org/2024/07/introducing-goodjob-v4 --- judoscale-good_job/judoscale-good_job.gemspec | 2 +- judoscale-good_job/test/test_helper.rb | 10 +++ .../good_job-multi-db-sample/Gemfile.lock | 68 +++++++++---------- ....rb => 20240708144259_create_good_jobs.rb} | 10 +++ .../db/good_job_db_schema.rb | 10 ++- sample-apps/good_job-sample/Gemfile.lock | 68 +++++++++---------- ....rb => 20240708143542_create_good_jobs.rb} | 10 +++ sample-apps/good_job-sample/db/schema.rb | 10 ++- 8 files changed, 117 insertions(+), 71 deletions(-) rename sample-apps/good_job-multi-db-sample/db/good_job_db_migrate/{20240430131249_create_good_jobs.rb => 20240708144259_create_good_jobs.rb} (85%) rename sample-apps/good_job-sample/db/migrate/{20240430130416_create_good_jobs.rb => 20240708143542_create_good_jobs.rb} (85%) diff --git a/judoscale-good_job/judoscale-good_job.gemspec b/judoscale-good_job/judoscale-good_job.gemspec index b10ad4c1..b2cde907 100644 --- a/judoscale-good_job/judoscale-good_job.gemspec +++ b/judoscale-good_job/judoscale-good_job.gemspec @@ -26,5 +26,5 @@ Gem::Specification.new do |spec| spec.required_ruby_version = ">= 2.6.0" spec.add_dependency "judoscale-ruby", Judoscale::VERSION - spec.add_dependency "good_job", ">= 3.0" + spec.add_dependency "good_job", ">= 3.0", "< 4.0" end diff --git a/judoscale-good_job/test/test_helper.rb b/judoscale-good_job/test/test_helper.rb index 7ec067d4..02078dfe 100644 --- a/judoscale-good_job/test/test_helper.rb +++ b/judoscale-good_job/test/test_helper.rb @@ -66,6 +66,8 @@ class TestRailsApp < Rails::Application t.text :job_class t.integer :error_event, limit: 2 t.text :labels, array: true + t.uuid :locked_by_id + t.datetime :locked_at end create_table :good_job_batches, id: :uuid do |t| @@ -94,11 +96,14 @@ class TestRailsApp < Rails::Application t.text :error t.integer :error_event, limit: 2 t.text :error_backtrace, array: true + t.uuid :process_id + t.interval :duration end create_table :good_job_processes, id: :uuid do |t| t.timestamps t.jsonb :state + t.integer :lock_type, limit: 2 end create_table :good_job_settings, id: :uuid do |t| @@ -124,6 +129,11 @@ class TestRailsApp < Rails::Application add_index :good_jobs, :labels, using: :gin, where: "(labels IS NOT NULL)", name: :index_good_jobs_on_labels add_index :good_job_executions, [:active_job_id, :created_at], name: :index_good_job_executions_on_active_job_id_and_created_at + add_index :good_jobs, [:priority, :scheduled_at], order: { priority: "ASC NULLS LAST", scheduled_at: :asc }, + where: "finished_at IS NULL AND locked_by_id IS NULL", name: :index_good_jobs_on_priority_scheduled_at_unfinished_unlocked + add_index :good_jobs, :locked_by_id, + where: "locked_by_id IS NOT NULL", name: "index_good_jobs_on_locked_by_id" + add_index :good_job_executions, [:process_id, :created_at], name: :index_good_job_executions_on_process_id_and_created_at end # standard:enable all end diff --git a/sample-apps/good_job-multi-db-sample/Gemfile.lock b/sample-apps/good_job-multi-db-sample/Gemfile.lock index c0614f40..13335f30 100644 --- a/sample-apps/good_job-multi-db-sample/Gemfile.lock +++ b/sample-apps/good_job-multi-db-sample/Gemfile.lock @@ -1,58 +1,58 @@ PATH remote: ../../judoscale-good_job specs: - judoscale-good_job (1.6.0) - good_job (>= 3.0) - judoscale-ruby (= 1.6.0) + judoscale-good_job (1.7.0) + good_job (>= 3.0, < 4.0) + judoscale-ruby (= 1.7.0) PATH remote: ../../judoscale-rails specs: - judoscale-rails (1.6.0) - judoscale-ruby (= 1.6.0) + judoscale-rails (1.7.0) + judoscale-ruby (= 1.7.0) railties PATH remote: ../../judoscale-ruby specs: - judoscale-ruby (1.6.0) + judoscale-ruby (1.7.0) GEM remote: https://rubygems.org/ specs: - actionpack (7.0.8.1) - actionview (= 7.0.8.1) - activesupport (= 7.0.8.1) + actionpack (7.0.8.4) + actionview (= 7.0.8.4) + activesupport (= 7.0.8.4) rack (~> 2.0, >= 2.2.4) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actionview (7.0.8.1) - activesupport (= 7.0.8.1) + actionview (7.0.8.4) + activesupport (= 7.0.8.4) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.8.1) - activesupport (= 7.0.8.1) + activejob (7.0.8.4) + activesupport (= 7.0.8.4) globalid (>= 0.3.6) - activemodel (7.0.8.1) - activesupport (= 7.0.8.1) - activerecord (7.0.8.1) - activemodel (= 7.0.8.1) - activesupport (= 7.0.8.1) - activesupport (7.0.8.1) + activemodel (7.0.8.4) + activesupport (= 7.0.8.4) + activerecord (7.0.8.4) + activemodel (= 7.0.8.4) + activesupport (= 7.0.8.4) + activesupport (7.0.8.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - builder (3.2.4) - concurrent-ruby (1.2.3) + builder (3.3.0) + concurrent-ruby (1.3.3) crass (1.0.6) debug (1.9.2) irb (~> 1.10) reline (>= 0.3.8) - erubi (1.12.0) + erubi (1.13.0) et-orbi (1.2.11) tzinfo fugit (1.11.0) @@ -60,14 +60,14 @@ GEM raabro (~> 1.4) globalid (1.2.1) activesupport (>= 6.1) - good_job (3.28.2) + good_job (3.99.0) activejob (>= 6.0.0) activerecord (>= 6.0.0) concurrent-ruby (>= 1.0.2) fugit (>= 1.1) railties (>= 6.0.0) thor (>= 0.14.1) - i18n (1.14.4) + i18n (1.14.5) concurrent-ruby (~> 1.0) io-console (0.7.2) irb (1.12.0) @@ -77,13 +77,13 @@ GEM crass (~> 1.0.2) nokogiri (>= 1.12.0) method_source (1.1.0) - minitest (5.22.3) + minitest (5.24.1) nio4r (2.7.1) - nokogiri (1.16.4-arm64-darwin) + nokogiri (1.16.6-arm64-darwin) racc (~> 1.4) - nokogiri (1.16.4-x86_64-darwin) + nokogiri (1.16.6-x86_64-darwin) racc (~> 1.4) - nokogiri (1.16.4-x86_64-linux) + nokogiri (1.16.6-x86_64-linux) racc (~> 1.4) pg (1.5.6) psych (5.1.2) @@ -91,7 +91,7 @@ GEM puma (5.6.8) nio4r (~> 2.0) raabro (1.4.0) - racc (1.7.3) + racc (1.8.0) rack (2.2.9) rack-test (2.1.0) rack (>= 1.3) @@ -102,9 +102,9 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.0.8.1) - actionpack (= 7.0.8.1) - activesupport (= 7.0.8.1) + railties (7.0.8.4) + actionpack (= 7.0.8.4) + activesupport (= 7.0.8.4) method_source rake (>= 12.2) thor (~> 1.0) @@ -118,7 +118,7 @@ GEM thor (1.3.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - zeitwerk (2.6.13) + zeitwerk (2.6.16) PLATFORMS arm64-darwin-20 @@ -144,4 +144,4 @@ DEPENDENCIES railties (~> 7.0.1) BUNDLED WITH - 2.5.4 + 2.5.11 diff --git a/sample-apps/good_job-multi-db-sample/db/good_job_db_migrate/20240430131249_create_good_jobs.rb b/sample-apps/good_job-multi-db-sample/db/good_job_db_migrate/20240708144259_create_good_jobs.rb similarity index 85% rename from sample-apps/good_job-multi-db-sample/db/good_job_db_migrate/20240430131249_create_good_jobs.rb rename to sample-apps/good_job-multi-db-sample/db/good_job_db_migrate/20240708144259_create_good_jobs.rb index 5dd8fe25..6cfd2445 100644 --- a/sample-apps/good_job-multi-db-sample/db/good_job_db_migrate/20240430131249_create_good_jobs.rb +++ b/sample-apps/good_job-multi-db-sample/db/good_job_db_migrate/20240708144259_create_good_jobs.rb @@ -30,6 +30,8 @@ def change t.text :job_class t.integer :error_event, limit: 2 t.text :labels, array: true + t.uuid :locked_by_id + t.datetime :locked_at end create_table :good_job_batches, id: :uuid do |t| @@ -58,11 +60,14 @@ def change t.text :error t.integer :error_event, limit: 2 t.text :error_backtrace, array: true + t.uuid :process_id + t.interval :duration end create_table :good_job_processes, id: :uuid do |t| t.timestamps t.jsonb :state + t.integer :lock_type, limit: 2 end create_table :good_job_settings, id: :uuid do |t| @@ -88,5 +93,10 @@ def change add_index :good_jobs, :labels, using: :gin, where: "(labels IS NOT NULL)", name: :index_good_jobs_on_labels add_index :good_job_executions, [:active_job_id, :created_at], name: :index_good_job_executions_on_active_job_id_and_created_at + add_index :good_jobs, [:priority, :scheduled_at], order: { priority: "ASC NULLS LAST", scheduled_at: :asc }, + where: "finished_at IS NULL AND locked_by_id IS NULL", name: :index_good_jobs_on_priority_scheduled_at_unfinished_unlocked + add_index :good_jobs, :locked_by_id, + where: "locked_by_id IS NOT NULL", name: "index_good_jobs_on_locked_by_id" + add_index :good_job_executions, [:process_id, :created_at], name: :index_good_job_executions_on_process_id_and_created_at end end diff --git a/sample-apps/good_job-multi-db-sample/db/good_job_db_schema.rb b/sample-apps/good_job-multi-db-sample/db/good_job_db_schema.rb index d69b21d2..33e92680 100644 --- a/sample-apps/good_job-multi-db-sample/db/good_job_db_schema.rb +++ b/sample-apps/good_job-multi-db-sample/db/good_job_db_schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_04_30_131249) do +ActiveRecord::Schema[7.0].define(version: 2024_07_08_144259) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" enable_extension "timescaledb" @@ -43,13 +43,17 @@ t.text "error" t.integer "error_event", limit: 2 t.text "error_backtrace", array: true + t.uuid "process_id" + t.interval "duration" t.index ["active_job_id", "created_at"], name: "index_good_job_executions_on_active_job_id_and_created_at" + t.index ["process_id", "created_at"], name: "index_good_job_executions_on_process_id_and_created_at" end create_table "good_job_processes", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false t.jsonb "state" + t.integer "lock_type", limit: 2 end create_table "good_job_settings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -82,6 +86,8 @@ t.text "job_class" t.integer "error_event", limit: 2 t.text "labels", array: true + t.uuid "locked_by_id" + t.datetime "locked_at" t.index ["active_job_id", "created_at"], name: "index_good_jobs_on_active_job_id_and_created_at" t.index ["batch_callback_id"], name: "index_good_jobs_on_batch_callback_id", where: "(batch_callback_id IS NOT NULL)" t.index ["batch_id"], name: "index_good_jobs_on_batch_id", where: "(batch_id IS NOT NULL)" @@ -90,8 +96,10 @@ t.index ["cron_key", "cron_at"], name: "index_good_jobs_on_cron_key_and_cron_at_cond", unique: true, where: "(cron_key IS NOT NULL)" t.index ["finished_at"], name: "index_good_jobs_jobs_on_finished_at", where: "((retried_good_job_id IS NULL) AND (finished_at IS NOT NULL))" t.index ["labels"], name: "index_good_jobs_on_labels", where: "(labels IS NOT NULL)", using: :gin + t.index ["locked_by_id"], name: "index_good_jobs_on_locked_by_id", where: "(locked_by_id IS NOT NULL)" t.index ["priority", "created_at"], name: "index_good_job_jobs_for_candidate_lookup", where: "(finished_at IS NULL)" t.index ["priority", "created_at"], name: "index_good_jobs_jobs_on_priority_created_at_when_unfinished", order: { priority: "DESC NULLS LAST" }, where: "(finished_at IS NULL)" + t.index ["priority", "scheduled_at"], name: "index_good_jobs_on_priority_scheduled_at_unfinished_unlocked", where: "((finished_at IS NULL) AND (locked_by_id IS NULL))" t.index ["queue_name", "scheduled_at"], name: "index_good_jobs_on_queue_name_and_scheduled_at", where: "(finished_at IS NULL)" t.index ["scheduled_at"], name: "index_good_jobs_on_scheduled_at", where: "(finished_at IS NULL)" end diff --git a/sample-apps/good_job-sample/Gemfile.lock b/sample-apps/good_job-sample/Gemfile.lock index 68ea4b7b..a9ecc936 100644 --- a/sample-apps/good_job-sample/Gemfile.lock +++ b/sample-apps/good_job-sample/Gemfile.lock @@ -1,55 +1,55 @@ PATH remote: ../../judoscale-good_job specs: - judoscale-good_job (1.6.0) - good_job (>= 3.0) - judoscale-ruby (= 1.6.0) + judoscale-good_job (1.7.0) + good_job (>= 3.0, < 4.0) + judoscale-ruby (= 1.7.0) PATH remote: ../../judoscale-rails specs: - judoscale-rails (1.6.0) - judoscale-ruby (= 1.6.0) + judoscale-rails (1.7.0) + judoscale-ruby (= 1.7.0) railties PATH remote: ../../judoscale-ruby specs: - judoscale-ruby (1.6.0) + judoscale-ruby (1.7.0) GEM remote: https://rubygems.org/ specs: - actionpack (7.0.8.1) - actionview (= 7.0.8.1) - activesupport (= 7.0.8.1) + actionpack (7.0.8.4) + actionview (= 7.0.8.4) + activesupport (= 7.0.8.4) rack (~> 2.0, >= 2.2.4) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actionview (7.0.8.1) - activesupport (= 7.0.8.1) + actionview (7.0.8.4) + activesupport (= 7.0.8.4) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.8.1) - activesupport (= 7.0.8.1) + activejob (7.0.8.4) + activesupport (= 7.0.8.4) globalid (>= 0.3.6) - activemodel (7.0.8.1) - activesupport (= 7.0.8.1) - activerecord (7.0.8.1) - activemodel (= 7.0.8.1) - activesupport (= 7.0.8.1) - activesupport (7.0.8.1) + activemodel (7.0.8.4) + activesupport (= 7.0.8.4) + activerecord (7.0.8.4) + activemodel (= 7.0.8.4) + activesupport (= 7.0.8.4) + activesupport (7.0.8.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - builder (3.2.4) - concurrent-ruby (1.2.3) + builder (3.3.0) + concurrent-ruby (1.3.3) crass (1.0.6) - erubi (1.12.0) + erubi (1.13.0) et-orbi (1.2.11) tzinfo fugit (1.11.0) @@ -57,32 +57,32 @@ GEM raabro (~> 1.4) globalid (1.2.1) activesupport (>= 6.1) - good_job (3.28.2) + good_job (3.99.0) activejob (>= 6.0.0) activerecord (>= 6.0.0) concurrent-ruby (>= 1.0.2) fugit (>= 1.1) railties (>= 6.0.0) thor (>= 0.14.1) - i18n (1.14.4) + i18n (1.14.5) concurrent-ruby (~> 1.0) loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) method_source (1.1.0) - minitest (5.22.3) + minitest (5.24.1) nio4r (2.7.1) - nokogiri (1.16.4-arm64-darwin) + nokogiri (1.16.6-arm64-darwin) racc (~> 1.4) - nokogiri (1.16.4-x86_64-darwin) + nokogiri (1.16.6-x86_64-darwin) racc (~> 1.4) - nokogiri (1.16.4-x86_64-linux) + nokogiri (1.16.6-x86_64-linux) racc (~> 1.4) pg (1.5.6) puma (5.6.8) nio4r (~> 2.0) raabro (1.4.0) - racc (1.7.3) + racc (1.8.0) rack (2.2.9) rack-test (2.1.0) rack (>= 1.3) @@ -93,9 +93,9 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.0.8.1) - actionpack (= 7.0.8.1) - activesupport (= 7.0.8.1) + railties (7.0.8.4) + actionpack (= 7.0.8.4) + activesupport (= 7.0.8.4) method_source rake (>= 12.2) thor (~> 1.0) @@ -104,7 +104,7 @@ GEM thor (1.3.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - zeitwerk (2.6.13) + zeitwerk (2.6.16) PLATFORMS arm64-darwin-20 @@ -128,4 +128,4 @@ DEPENDENCIES railties (~> 7.0.1) BUNDLED WITH - 2.5.4 + 2.5.11 diff --git a/sample-apps/good_job-sample/db/migrate/20240430130416_create_good_jobs.rb b/sample-apps/good_job-sample/db/migrate/20240708143542_create_good_jobs.rb similarity index 85% rename from sample-apps/good_job-sample/db/migrate/20240430130416_create_good_jobs.rb rename to sample-apps/good_job-sample/db/migrate/20240708143542_create_good_jobs.rb index 5dd8fe25..6cfd2445 100644 --- a/sample-apps/good_job-sample/db/migrate/20240430130416_create_good_jobs.rb +++ b/sample-apps/good_job-sample/db/migrate/20240708143542_create_good_jobs.rb @@ -30,6 +30,8 @@ def change t.text :job_class t.integer :error_event, limit: 2 t.text :labels, array: true + t.uuid :locked_by_id + t.datetime :locked_at end create_table :good_job_batches, id: :uuid do |t| @@ -58,11 +60,14 @@ def change t.text :error t.integer :error_event, limit: 2 t.text :error_backtrace, array: true + t.uuid :process_id + t.interval :duration end create_table :good_job_processes, id: :uuid do |t| t.timestamps t.jsonb :state + t.integer :lock_type, limit: 2 end create_table :good_job_settings, id: :uuid do |t| @@ -88,5 +93,10 @@ def change add_index :good_jobs, :labels, using: :gin, where: "(labels IS NOT NULL)", name: :index_good_jobs_on_labels add_index :good_job_executions, [:active_job_id, :created_at], name: :index_good_job_executions_on_active_job_id_and_created_at + add_index :good_jobs, [:priority, :scheduled_at], order: { priority: "ASC NULLS LAST", scheduled_at: :asc }, + where: "finished_at IS NULL AND locked_by_id IS NULL", name: :index_good_jobs_on_priority_scheduled_at_unfinished_unlocked + add_index :good_jobs, :locked_by_id, + where: "locked_by_id IS NOT NULL", name: "index_good_jobs_on_locked_by_id" + add_index :good_job_executions, [:process_id, :created_at], name: :index_good_job_executions_on_process_id_and_created_at end end diff --git a/sample-apps/good_job-sample/db/schema.rb b/sample-apps/good_job-sample/db/schema.rb index d89c0d6e..ad54fdec 100644 --- a/sample-apps/good_job-sample/db/schema.rb +++ b/sample-apps/good_job-sample/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_04_30_130416) do +ActiveRecord::Schema[7.0].define(version: 2024_07_08_143542) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" enable_extension "timescaledb" @@ -43,13 +43,17 @@ t.text "error" t.integer "error_event", limit: 2 t.text "error_backtrace", array: true + t.uuid "process_id" + t.interval "duration" t.index ["active_job_id", "created_at"], name: "index_good_job_executions_on_active_job_id_and_created_at" + t.index ["process_id", "created_at"], name: "index_good_job_executions_on_process_id_and_created_at" end create_table "good_job_processes", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false t.jsonb "state" + t.integer "lock_type", limit: 2 end create_table "good_job_settings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -82,6 +86,8 @@ t.text "job_class" t.integer "error_event", limit: 2 t.text "labels", array: true + t.uuid "locked_by_id" + t.datetime "locked_at" t.index ["active_job_id", "created_at"], name: "index_good_jobs_on_active_job_id_and_created_at" t.index ["batch_callback_id"], name: "index_good_jobs_on_batch_callback_id", where: "(batch_callback_id IS NOT NULL)" t.index ["batch_id"], name: "index_good_jobs_on_batch_id", where: "(batch_id IS NOT NULL)" @@ -90,8 +96,10 @@ t.index ["cron_key", "cron_at"], name: "index_good_jobs_on_cron_key_and_cron_at_cond", unique: true, where: "(cron_key IS NOT NULL)" t.index ["finished_at"], name: "index_good_jobs_jobs_on_finished_at", where: "((retried_good_job_id IS NULL) AND (finished_at IS NOT NULL))" t.index ["labels"], name: "index_good_jobs_on_labels", where: "(labels IS NOT NULL)", using: :gin + t.index ["locked_by_id"], name: "index_good_jobs_on_locked_by_id", where: "(locked_by_id IS NOT NULL)" t.index ["priority", "created_at"], name: "index_good_job_jobs_for_candidate_lookup", where: "(finished_at IS NULL)" t.index ["priority", "created_at"], name: "index_good_jobs_jobs_on_priority_created_at_when_unfinished", order: { priority: "DESC NULLS LAST" }, where: "(finished_at IS NULL)" + t.index ["priority", "scheduled_at"], name: "index_good_jobs_on_priority_scheduled_at_unfinished_unlocked", where: "((finished_at IS NULL) AND (locked_by_id IS NULL))" t.index ["queue_name", "scheduled_at"], name: "index_good_jobs_on_queue_name_and_scheduled_at", where: "(finished_at IS NULL)" t.index ["scheduled_at"], name: "index_good_jobs_on_scheduled_at", where: "(finished_at IS NULL)" end