覚書: Rails: Solid Queue
外観
SQLite で Solid Queue を使った際の覚書です。
リンク
https://dev.37signals.com/introducing-solid-queue/
https://dev.37signals.com/mission-control-jobs/
https://techracho.bpsinc.jp/hachi8833/2024_02_09/139102
https://github.com/usutani/study_solid_queue
https://techracho.bpsinc.jp/hachi8833/2020_09_30/96694
https://note.com/usutani/n/n1d698cae89f1
https://note.com/usutani/n/nf0f28cd6c37d
環境
ruby 3.2.2
Rails 7.1.3.2
sqlite3 (1.7.3)
solid_queue (0.3.0)
mission_control-jobs (0.2.0)
Solid Queue
準備
https://github.com/rails/solid_queue
rails new study_solid_queue
cd study_solid_queue
Gemfile
gem "solid_queue"
bundle install
bin/rails generate solid_queue:install
bin/rails db:migrate
設定変更/追加
production.rb, development.rb
config.active_job.queue_adapter = :solid_queue
config.solid_queue.use_skip_locked = false
puma.rb
plugin :solid_queue
ジョブとコントローラ
bin/rails generate job hello
def perform(*args)
logger.info "*" * 100
end
bin/rails generate controller hello index
class HelloController < ApplicationController
def index
HelloJob.set(wait_until: Time.current + 3.seconds).perform_later
head :ok
end
end
routes.rb
get "hello/index"
root "hello#index"
bin/rails server
定期的なタスク
solid_queue.yml
default: &default
dispatchers:
- polling_interval: 1
batch_size: 500
recurring_tasks:
periodic_hello:
class: HelloJob
schedule: every minute
# ...
bin/rails server
Mission Control — Jobs
https://github.com/rails/mission_control-jobs
Gemfile
gem "mission_control-jobs"
bundle install
Rails.application.routes.draw do
# ...
mount MissionControl::Jobs::Engine, at: "/jobs"
bin/rails server
open http://localhost:3000/jobs
以上です。
この記事が気に入ったらサポートをしてみませんか?