Skip to content

Commit

Permalink
resqueをsolid solid_queueに置き換えた
Browse files Browse the repository at this point in the history
  • Loading branch information
miminashi committed Aug 10, 2024
1 parent adfb7ee commit dafca03
Show file tree
Hide file tree
Showing 15 changed files with 285 additions and 85 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ gem "bootsnap", require: false
gem "image_processing", "~> 1.2"

# for background jobs
gem "resque"
gem "solid_queue"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
Expand Down
38 changes: 14 additions & 24 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
concurrent-ruby (1.3.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
crass (1.0.6)
cuprite (0.15.1)
Expand All @@ -106,13 +106,18 @@ GEM
reline (>= 0.3.8)
drb (2.2.1)
erubi (1.13.0)
et-orbi (1.2.11)
tzinfo
ferrum (0.15)
addressable (~> 2.5)
concurrent-ruby (~> 1.1)
webrick (~> 1.7)
websocket-driver (~> 0.7)
ffi (1.17.0-x86_64-darwin)
ffi (1.17.0-x86_64-linux-gnu)
fugit (1.11.0)
et-orbi (~> 1, >= 1.2.11)
raabro (~> 1.4)
globalid (1.2.1)
activesupport (>= 6.1)
i18n (1.14.5)
Expand Down Expand Up @@ -145,11 +150,7 @@ GEM
mini_magick (4.13.2)
mini_mime (1.1.5)
minitest (5.24.1)
mono_logger (1.1.2)
msgpack (1.7.2)
multi_json (1.15.0)
mustermann (3.0.2)
ruby2_keywords (~> 0.0.1)
mutex_m (0.2.0)
net-imap (0.4.14)
date
Expand All @@ -171,11 +172,9 @@ GEM
public_suffix (6.0.1)
puma (6.4.2)
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.8.1)
rack (3.1.7)
rack-protection (4.0.0)
base64 (>= 0.1.0)
rack (>= 3.0.0, < 4)
rack-session (2.0.0)
rack (>= 3.0.0)
rack-test (2.1.0)
Expand Down Expand Up @@ -216,26 +215,18 @@ GEM
rdoc (6.7.0)
psych (>= 4.0.0)
redis (4.8.1)
redis-namespace (1.11.0)
redis (>= 4)
regexp_parser (2.9.2)
reline (0.5.9)
io-console (~> 0.5)
resque (2.6.0)
mono_logger (~> 1.0)
multi_json (~> 1.0)
redis-namespace (~> 1.6)
sinatra (>= 0.9.2)
ruby-vips (2.2.2)
ffi (~> 1.12)
logger
ruby2_keywords (0.0.5)
sinatra (4.0.0)
mustermann (~> 3.0)
rack (>= 3.0.0, < 4)
rack-protection (= 4.0.0)
rack-session (>= 2.0.0, < 3)
tilt (~> 2.0)
solid_queue (0.4.1)
activejob (>= 7.1)
activerecord (>= 7.1)
concurrent-ruby (>= 1.3.1)
fugit (~> 1.11.0)
railties (>= 7.1)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand All @@ -247,7 +238,6 @@ GEM
railties (>= 6.0.0)
stringio (3.1.1)
thor (1.3.1)
tilt (2.4.0)
timeout (0.4.1)
turbo-rails (2.0.6)
actionpack (>= 6.0.0)
Expand Down Expand Up @@ -285,7 +275,7 @@ DEPENDENCIES
puma (~> 6.0)
rails (= 7.1)
redis (~> 4.0)
resque
solid_queue
sprockets-rails
stimulus-rails
turbo-rails
Expand Down
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ class Application < Rails::Application
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")

config.active_job.queue_adapter = :solid_queue
end
end
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
config.action_controller.raise_on_missing_callback_actions = true

# Use Resque as ActiveJob Adapter
config.active_job.queue_adapter = :resque
# config.active_job.queue_adapter = :resque

# ActiveStorageのURLの期限切れを伸ばす
# - 動画の再生が5分で途切れる問題のワークアラウンド
Expand Down
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,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 = "ytdlor_production"

config.action_mailer.perform_caching = false
Expand Down
6 changes: 0 additions & 6 deletions config/initializers/resque.rb

This file was deleted.

3 changes: 0 additions & 3 deletions config/resque.yml

This file was deleted.

26 changes: 26 additions & 0 deletions config/solid_queue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
default: &default
dispatchers:
- polling_interval: 1
batch_size: 500
workers:
- queues: "default"
threads: 1
processes: 1
polling_interval: 1
- queues: "thumbnail"
threads: 1
processes: 1
polling_interval: 1
- queues: "video"
threads: 1
processes: 1
polling_interval: 1

development:
<<: *default

test:
<<: *default

production:
<<: *default
101 changes: 101 additions & 0 deletions db/migrate/20240810224902_create_solid_queue_tables.solid_queue.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit dafca03

Please sign in to comment.