From 55828668bf951c2c3d2c1af372880d751bb93078 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 19 Apr 2023 12:33:27 +0900 Subject: [PATCH] Switch to use good_job from sidekiq --- .gitignore | 1 - Gemfile | 2 +- Gemfile.local | 2 +- Gemfile.lock | 25 ++++--- Procfile | 2 +- config/additional_environment.rb | 2 +- config/database.yml | 21 ++++++ config/initializers/sidekiq.rb | 7 -- db/migrate/20230419033541_create_good_jobs.rb | 66 +++++++++++++++++++ docker-compose.yml | 8 +++ 10 files changed, 115 insertions(+), 21 deletions(-) create mode 100644 config/database.yml delete mode 100644 config/initializers/sidekiq.rb create mode 100644 db/migrate/20230419033541_create_good_jobs.rb create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore index a71404a25f..ce6179e785 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ /.loadpath /.powrc /.rvmrc -/config/database.yml /config/email.yml /config/secrets.yml /config/initializers/session_store.rb diff --git a/Gemfile b/Gemfile index 3b8ae20def..1f18e6d00f 100644 --- a/Gemfile +++ b/Gemfile @@ -69,7 +69,7 @@ if File.exist?(database_file) when 'mysql2' gem "mysql2", "~> 0.5.0", :platforms => [:mri, :mingw, :x64_mingw] when /postgresql/ - gem "pg", "~> 1.2.2", :platforms => [:mri, :mingw, :x64_mingw] + # gem "pg", "~> 1.2.2", :platforms => [:mri, :mingw, :x64_mingw] when /sqlite3/ gem "sqlite3", "~> 1.4.0", :platforms => [:mri, :mingw, :x64_mingw] when /sqlserver/ diff --git a/Gemfile.local b/Gemfile.local index 837a752b96..4e1f818802 100644 --- a/Gemfile.local +++ b/Gemfile.local @@ -1,9 +1,9 @@ ruby ENV['CUSTOM_RUBY_VERSION'] || '~> 3.2.2' gem 'puma' +gem 'good_job' gem 'pg' gem 'rack-protection' -gem 'sidekiq' group :development do gem 'pry-rails' diff --git a/Gemfile.lock b/Gemfile.lock index a10c50bbf5..afda582bc3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -101,7 +101,6 @@ GEM coderay (1.1.3) commonmarker (0.23.9) concurrent-ruby (1.2.2) - connection_pool (2.4.0) crass (1.0.6) css_parser (1.14.0) addressable @@ -115,9 +114,22 @@ GEM dotenv (= 2.8.1) railties (>= 3.2) erubi (1.12.0) + et-orbi (1.2.7) + tzinfo ffi (1.15.5) + fugit (1.8.1) + et-orbi (~> 1, >= 1.2.7) + raabro (~> 1.4) globalid (1.1.0) activesupport (>= 5.0) + good_job (3.15.1) + activejob (>= 6.0.0) + activerecord (>= 6.0.0) + concurrent-ruby (>= 1.0.2) + fugit (>= 1.1) + railties (>= 6.0.0) + thor (>= 0.14.1) + webrick (>= 1.3) html-pipeline (2.13.2) activesupport (>= 2) nokogiri (>= 1.4) @@ -175,6 +187,7 @@ GEM public_suffix (5.0.1) puma (6.2.2) nio4r (~> 2.0) + raabro (1.4.0) racc (1.6.2) rack (2.2.6.4) rack-protection (3.0.6) @@ -218,8 +231,6 @@ GEM rbpdf-font (1.19.1) rbtree3 (0.7.0) redcarpet (3.5.1) - redis-client (0.14.1) - connection_pool redmine_crm (0.0.59) liquid (< 2.6.4) rails @@ -267,11 +278,6 @@ GEM selenium-webdriver (3.142.7) childprocess (>= 0.5, < 4.0) rubyzip (>= 1.2.2) - sidekiq (7.0.9) - concurrent-ruby (< 2) - connection_pool (>= 2.3.0) - rack (>= 2.2.4) - redis-client (>= 0.11.0) simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) @@ -295,6 +301,7 @@ GEM nokogiri (~> 1.6) rubyzip (>= 1.3.0) selenium-webdriver (>= 3.0, < 4.0) + webrick (1.8.1) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -321,6 +328,7 @@ DEPENDENCIES deckar01-task_list (= 2.3.2) dotenv-rails ffi + good_job html-pipeline (~> 2.13.2) i18n (~> 1.10.0) listen (~> 3.3) @@ -356,7 +364,6 @@ DEPENDENCIES rubyzip (~> 2.3.0) sanitize (~> 6.0) selenium-webdriver (~> 3.142.7) - sidekiq simplecov (~> 0.21.2) tzinfo-data webdrivers (= 4.6.1) diff --git a/Procfile b/Procfile index 67c08e2ec2..57812a86b4 100644 --- a/Procfile +++ b/Procfile @@ -1,3 +1,3 @@ release: bundle exec rake db:migrate redmine:plugins:migrate RAILS_ENV=production web: RUBYOPT=--jit bundle exec puma -C config/puma.rb -worker: RUBYOPT=--jit bundle exec sidekiq -C config/sidekiq.yml +worker: RUBYOPT=--jit bundle exec good_job --max-threads=5 diff --git a/config/additional_environment.rb b/config/additional_environment.rb index 4815479c19..903820b397 100644 --- a/config/additional_environment.rb +++ b/config/additional_environment.rb @@ -11,7 +11,7 @@ if Rails.env.production? config.log_level = :info config.force_ssl = true - config.active_job.queue_adapter = :sidekiq + config.active_job.queue_adapter = :good_job end Dir.glob(Rails.root.join("plugins/*/lib").to_s).each do |path| diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000000..9d268ad5a7 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,21 @@ +default: &default + adapter: postgresql + encoding: utf8 + username: postgres + +development: + <<: *default + database: rubygems_development + host: localhost + password: devpassword + pool: 5 + timeout: 5000 + +test: + <<: *default + database: rubygems_test + host: localhost + min_messages: warning + password: testpassword + pool: 5 + timeout: 5000 diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb deleted file mode 100644 index c48499c7e5..0000000000 --- a/config/initializers/sidekiq.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sidekiq.configure_server do |config| - config.redis = { ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE } } -end - -Sidekiq.configure_client do |config| - config.redis = { ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE } } -end diff --git a/db/migrate/20230419033541_create_good_jobs.rb b/db/migrate/20230419033541_create_good_jobs.rb new file mode 100644 index 0000000000..90b54cf831 --- /dev/null +++ b/db/migrate/20230419033541_create_good_jobs.rb @@ -0,0 +1,66 @@ +# 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.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 + 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_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" + end +end diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000..7c3f19b18d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3' +services: + db: + image: postgres:11.13 + ports: + - "5432:5432" + environment: + - POSTGRES_HOST_AUTH_METHOD=trust