From d1fcc022a3e071849dc488f48713ea75302b58a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Delmaire?= Date: Sat, 21 Oct 2023 11:20:59 +0200 Subject: [PATCH] Migrate from sidekiq to good_job --- Gemfile | 3 +- Gemfile.lock | 19 ++-- config/application.rb | 2 +- config/credentials/production.yml.enc | 2 +- config/credentials/test.yml.enc | 2 +- config/initializers/good_job.rb | 4 + config/initializers/sidekiq.rb | 17 ---- config/routes.rb | 11 +-- config/schedule.yml | 2 - db/migrate/20231020161819_create_good_jobs.rb | 88 +++++++++++++++++++ db/schema.rb | 79 ++++++++++++++++- docker-compose.yml | 5 +- 12 files changed, 188 insertions(+), 46 deletions(-) create mode 100644 config/initializers/good_job.rb delete mode 100644 config/initializers/sidekiq.rb create mode 100644 db/migrate/20231020161819_create_good_jobs.rb diff --git a/Gemfile b/Gemfile index a74a19175d..d7882235e9 100644 --- a/Gemfile +++ b/Gemfile @@ -27,8 +27,7 @@ gem 'bcrypt', '~> 3.1.19' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development -gem 'sidekiq' -gem 'sidekiq-cron' +gem 'good_job' gem 'draper' gem 'ip_anonymizer' diff --git a/Gemfile.lock b/Gemfile.lock index 37bd7e5ae8..519393481e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -180,6 +180,13 @@ GEM rails (>= 4.0.0) globalid (1.2.1) activesupport (>= 6.1) + good_job (3.19.4) + activejob (>= 6.0.0) + activerecord (>= 6.0.0) + concurrent-ruby (>= 1.0.2) + fugit (>= 1.1) + railties (>= 6.0.0) + thor (>= 0.14.1) guard (2.18.1) formatador (>= 0.2.4) listen (>= 2.7, < 4.0) @@ -469,15 +476,6 @@ GEM shellany (0.0.1) shoulda-matchers (5.3.0) activesupport (>= 5.2.0) - sidekiq (7.1.6) - concurrent-ruby (< 2) - connection_pool (>= 2.3.0) - rack (>= 2.2.4) - redis-client (>= 0.14.0) - sidekiq-cron (1.10.1) - fugit (~> 1.8) - globalid (>= 1.0.1) - sidekiq (>= 6) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) @@ -564,6 +562,7 @@ DEPENDENCIES draper factory_bot_rails gaffe + good_job guard-rspec i18n-tasks interactor @@ -600,8 +599,6 @@ DEPENDENCIES sentry-rails sentry-ruby shoulda-matchers - sidekiq - sidekiq-cron simplecov simplecov-console sitemap_generator diff --git a/config/application.rb b/config/application.rb index 53e17ceda0..9af43cb3da 100644 --- a/config/application.rb +++ b/config/application.rb @@ -36,7 +36,7 @@ class Application < Rails::Application config.middleware.insert_after ActionDispatch::RemoteIp, IpAnonymizer::HashIp, key: Rails.application.credentials.ip_anonymizer_key - config.active_job.queue_adapter = :sidekiq + config.active_job.queue_adapter = :good_job config.active_job.queue_name_prefix = "admin_api_entreprise_#{Rails.env}" config.action_mailer.deliver_later_queue_name = :default diff --git a/config/credentials/production.yml.enc b/config/credentials/production.yml.enc index 827e023f52..800d452359 100644 --- a/config/credentials/production.yml.enc +++ b/config/credentials/production.yml.enc @@ -1 +1 @@ -sUaIU6RcjkR11ZzOoIvOIH6aeDUZBRMHK5Hqtnt3fzbn1CIwe6YpNHbRqyiK/LYzQdJOJfVvl8JWbnInjp/m86YqLqphp6RSNxqFyZ+LBxCLmFU5cjIkOOgNo9Dhdd4R4RqsRPWKJzRaoH2cIvYCExn3sxa/cvLJbCUQ/VdcPlHexXrJn+9kxeONzCoDuXMKrGZitLI39gau3lMEDXMiFkD70YUow1E8N8i9u4Uu/UsxhF8+zJMy/VGGGL3kyeg5iR6MsOnBB3KV02M9DIs6dlHdwJ1gKHSuRbuEQo1eS61ugAi6Gy5eVsjgmI+EUMnR1LwVXqRAGVrhoRCwHFuePKdrjbvuJ0AlBetA/ZTte5PHcBb31UUDoZco6lgtVdIrhZ71KxLWYqVjXXKayRjR7l27UyzyOSXVhHC4LKO8G+J/6uHEhUOJAknfpS+VASImQTF0tqNZr3nzR5s0+MH9FG1YrL4h6oBRkMOmWOejC65hs34ksWG83X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h+yCAY2sdpq29EKs63CCr1MPab3UsTgAVpNtYcuuuWRLnbNf1tGZUV3UfinR5qHWDcymmtDIK8VxLoGZZjO3v9rdmFD/jMsIHtk5AIh4FU8PmMKtfKnbc6an0pknO52PzvR+m8pLN0FFOBGInilvyd/7eZEfRp9gYTwE4GgyROAcwfX2z60cDbqyZY8C3wI0lHp2kkm3O62kNO4KnZjiUBikHxLj1rCCyYNn7Q+3Y7+zmKiH8w98Yp9gHdkHUojUhlZaoENvZXEPyw+2544tCcPieArcnZ83HGVwC6kdTdgzlJYUJ4xzi3SKHuJ7Kwjh4OoL3xJ6+wsZf+7VsXvfFdKsLEmadxgKYZ793RQQOwBLaNqxAd6T5Z2PUayhTXfpti83BpkT0qmH5ddDmMSW8sVgiY0lz1fiMVRkrsMVasGd4=--vVO53cgf2j5u6ctd--jxW9FDy+n0r4EXc4nlWOgQ== \ No newline at end of file diff --git a/config/credentials/test.yml.enc b/config/credentials/test.yml.enc index cc1c1eed0e..24ce93f048 100644 --- a/config/credentials/test.yml.enc +++ b/config/credentials/test.yml.enc @@ -1 +1 @@ -9ytiJpAK0kCF8NSBuhnCLM4go6PLgkdJdrd5fW0L+OgoplHKXiSRvGFHuyuJITPvQsYiXO/eVtHWVAgQvA9S4B/BjPabYatx8H+/BZRZiHQ93Yenk6RllFNdA8z6nGKs/elg7Zopbs17kde0hseX6QyicZ/SzOi0cfD+kzQU9gOU8dlWJZu/qc+kVSJUc+k249B3E4kYrxHNTjNXHZVgJWb/xNhXaI01CS/L9BSAIvGnX6UVHfUaIuvMz3i+5VdvnIpAnqirbtSbfFfjgTTYPVTCMi6l6qeakOzgIotTwg/6500Qj443dqSvh0SBld6dbmHGbRhpCfPTF8+77CA6Ai33f7soUQG3ihv3poVJPykUZSjIWrK8fMYNvKfGFyI8LBZa1ypl9rYV4+H0ivy2LMzWSzvWawNvwQLF1eSOyglbFAowcpvkcAdz4KOM3aGXWtGLtRWjDN5BizRMSuKYzxISe9ggIthiIyGx2bDcL6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--git a/config/initializers/good_job.rb b/config/initializers/good_job.rb new file mode 100644 index 0000000000..6abda02bb8 --- /dev/null +++ b/config/initializers/good_job.rb @@ -0,0 +1,4 @@ +Rails.application.configure do + config.good_job.enable_cron = true + config.good_job.cron = Rails.application.config_for(:schedule) +end diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb deleted file mode 100644 index 5b41f630ca..0000000000 --- a/config/initializers/sidekiq.rb +++ /dev/null @@ -1,17 +0,0 @@ -Sidekiq.configure_server do |config| - config.redis = { url: ENV.fetch('REDIS_URL') { Rails.application.config_for(:redis)[:url] } } - - config.on(:startup) do - schedule_file = Rails.root.join('config/schedule.yml') - - if File.exist?(schedule_file) - loaded_conf = YAML.load_file(schedule_file, aliases: true) - end - - Sidekiq::Cron::Job.load_from_hash(loaded_conf[Rails.env]) - end -end - -Sidekiq.configure_client do |config| - config.redis = { url: ENV.fetch('REDIS_URL') { Rails.application.config_for(:redis)[:url] } } -end diff --git a/config/routes.rb b/config/routes.rb index fea85bde17..a0dab41ce5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,12 +1,9 @@ Rails.application.routes.draw do - require 'sidekiq/web' - require 'sidekiq/cron/web' - - Sidekiq::Web.use Rack::Auth::Basic do |username, password| - ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(username), ::Digest::SHA256.hexdigest(Rails.application.credentials.sidekiq_ui_username)) & - ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(password), ::Digest::SHA256.hexdigest(Rails.application.credentials.sidekiq_ui_password)) + GoodJob::Engine.middleware.use(Rack::Auth::Basic) do |username, password| + ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(username), ::Digest::SHA256.hexdigest(Rails.application.credentials.workers_ui_username)) & + ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(password), ::Digest::SHA256.hexdigest(Rails.application.credentials.workers_ui_password)) end - mount Sidekiq::Web => '/sidekiq' + mount GoodJob::Engine => '/workers' draw(:api_entreprise) draw(:api_particulier) diff --git a/config/schedule.yml b/config/schedule.yml index e0835749ec..6f6f937fa5 100644 --- a/config/schedule.yml +++ b/config/schedule.yml @@ -2,13 +2,11 @@ development: token_expiration_notice: cron: '0 1 * * *' class: 'TokenExpirationNoticeJob' - queue: default production: &deployed token_expiration_notice: cron: '0 */4 * * *' class: 'TokenExpirationNoticeJob' - queue: default staging: *deployed sandbox: *deployed diff --git a/db/migrate/20231020161819_create_good_jobs.rb b/db/migrate/20231020161819_create_good_jobs.rb new file mode 100644 index 0000000000..dbb6756cc4 --- /dev/null +++ b/db/migrate/20231020161819_create_good_jobs.rb @@ -0,0 +1,88 @@ +# frozen_string_literal: true + +class CreateGoodJobs < ActiveRecord::Migration[7.1] + def change + # Uncomment for Postgres v12 or earlier to enable gen_random_uuid() support + # enable_extension 'pgcrypto' + + create_table :good_jobs, id: :uuid do |t| + t.text :queue_name + t.integer :priority + t.jsonb :serialized_params + t.datetime :scheduled_at + t.datetime :performed_at + t.datetime :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.datetime :cron_at + + t.uuid :batch_id + t.uuid :batch_callback_id + + t.boolean :is_discrete + t.integer :executions_count + t.text :job_class + t.integer :error_event, limit: 2 + end + + create_table :good_job_batches, id: :uuid do |t| + t.timestamps + t.text :description + t.jsonb :serialized_properties + t.text :on_finish + t.text :on_success + t.text :on_discard + t.text :callback_queue_name + t.integer :callback_priority + t.datetime :enqueued_at + t.datetime :discarded_at + t.datetime :finished_at + end + + create_table :good_job_executions, id: :uuid do |t| + t.timestamps + + t.uuid :active_job_id, null: false + t.text :job_class + t.text :queue_name + t.jsonb :serialized_params + t.datetime :scheduled_at + t.datetime :finished_at + t.text :error + t.integer :error_event, limit: 2 + end + + create_table :good_job_processes, id: :uuid do |t| + t.timestamps + t.jsonb :state + end + + create_table :good_job_settings, id: :uuid do |t| + t.timestamps + t.text :key + t.jsonb :value + t.index :key, unique: true + 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 + add_index :good_jobs, [:active_job_id], name: :index_good_jobs_on_active_job_id + add_index :good_jobs, [:finished_at], where: "retried_good_job_id IS NULL AND finished_at IS NOT NULL", name: :index_good_jobs_jobs_on_finished_at + add_index :good_jobs, [:priority, :created_at], order: { priority: "DESC NULLS LAST", created_at: :asc }, + where: "finished_at IS NULL", name: :index_good_jobs_jobs_on_priority_created_at_when_unfinished + add_index :good_jobs, [:batch_id], where: "batch_id IS NOT NULL" + add_index :good_jobs, [:batch_callback_id], where: "batch_callback_id IS NOT NULL" + + add_index :good_job_executions, [:active_job_id, :created_at], name: :index_good_job_executions_on_active_job_id_and_created_at + end +end diff --git a/db/schema.rb b/db/schema.rb index 96aa2e5e10..f2c21162be 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2023_10_13_073346) do +ActiveRecord::Schema[7.1].define(version: 2023_10_20_161819) do # These are extensions that must be enabled in order to support this database enable_extension "btree_gin" enable_extension "pgcrypto" @@ -32,6 +32,83 @@ t.index ["external_id"], name: "index_authorization_requests_on_external_id", unique: true, where: "(external_id IS NOT NULL)" end + create_table "good_job_batches", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.text "description" + t.jsonb "serialized_properties" + t.text "on_finish" + t.text "on_success" + t.text "on_discard" + t.text "callback_queue_name" + t.integer "callback_priority" + t.datetime "enqueued_at" + t.datetime "discarded_at" + t.datetime "finished_at" + end + + create_table "good_job_executions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.uuid "active_job_id", null: false + t.text "job_class" + t.text "queue_name" + t.jsonb "serialized_params" + t.datetime "scheduled_at" + t.datetime "finished_at" + t.text "error" + t.integer "error_event", limit: 2 + t.index ["active_job_id", "created_at"], name: "index_good_job_executions_on_active_job_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" + end + + create_table "good_job_settings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.text "key" + t.jsonb "value" + t.index ["key"], name: "index_good_job_settings_on_key", unique: true + end + + create_table "good_jobs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.text "queue_name" + t.integer "priority" + t.jsonb "serialized_params" + t.datetime "scheduled_at" + t.datetime "performed_at" + t.datetime "finished_at" + t.text "error" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.uuid "active_job_id" + t.text "concurrency_key" + t.text "cron_key" + t.uuid "retried_good_job_id" + t.datetime "cron_at" + t.uuid "batch_id" + t.uuid "batch_callback_id" + t.boolean "is_discrete" + t.integer "executions_count" + t.text "job_class" + t.integer "error_event", limit: 2 + t.index ["active_job_id", "created_at"], name: "index_good_jobs_on_active_job_id_and_created_at" + t.index ["active_job_id"], name: "index_good_jobs_on_active_job_id" + 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)" + t.index ["concurrency_key"], name: "index_good_jobs_on_concurrency_key_when_unfinished", where: "(finished_at IS NULL)" + t.index ["cron_key", "created_at"], name: "index_good_jobs_on_cron_key_and_created_at" + t.index ["cron_key", "cron_at"], name: "index_good_jobs_on_cron_key_and_cron_at", unique: true + 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 ["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 ["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 + create_table "magic_links", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "email", null: false t.string "access_token", null: false diff --git a/docker-compose.yml b/docker-compose.yml index c657bcc304..2a9d816270 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,9 +29,9 @@ services: links: - db - redis - sidekiq: + workers: build: . - command: bundle exec sidekiq + command: bundle exec good_job start volumes: - .:/app depends_on: @@ -42,6 +42,5 @@ services: - redis environment: - RAILS_ENV=development - - REDIS_URL=redis://redis:6379/0 - POSTGRES_HOST=db - REDIS_HOST=redis