Skip to content

Commit

Permalink
Switch to use good_job from sidekiq
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt committed Apr 19, 2023
1 parent 19fab18 commit 5582866
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 21 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -3,7 +3,6 @@
/.loadpath
/.powrc
/.rvmrc
/config/database.yml
/config/email.yml
/config/secrets.yml
/config/initializers/session_store.rb
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion 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'
Expand Down
25 changes: 16 additions & 9 deletions Gemfile.lock
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion 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
2 changes: 1 addition & 1 deletion config/additional_environment.rb
Expand Up @@ -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|
Expand Down
21 changes: 21 additions & 0 deletions 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
7 changes: 0 additions & 7 deletions config/initializers/sidekiq.rb

This file was deleted.

66 changes: 66 additions & 0 deletions 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
8 changes: 8 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,8 @@
version: '3'
services:
db:
image: postgres:11.13
ports:
- "5432:5432"
environment:
- POSTGRES_HOST_AUTH_METHOD=trust

0 comments on commit 5582866

Please sign in to comment.