Sidekiq
インストール
Gemfile
# Sidekiq
gem 'sidekiq'
gem 'sidetiq'
gem 'sinatra', require: false
gem 'slim'
bundle install --path vendor/bundle
設定
config/initializers/sidekiq.rb
require "sidekiq/web"
require "sidetiq/web"
REDIS_URL = { url: 'redis://localhost:6379/1' }
Sidekiq.configure_server do |config|
config.redis = REDIS_URL
end
Sidekiq.configure_client do |config|
config.redis = REDIS_URL
end
Sidekiq::Web.use(Rack::Auth::Basic) do |user, password|
[user, password] == ["user", "password"]
end
sidekiqの起動設定
config/sidekiq.yml
:verbose: false
:daemon: true
:pidfile: tmp/pids/sidekiq.pid
:logfile: log/sidekiq.log
:concurrency: 5
:queues:
- default
管理画面のmount
config/routes.rb
Rails.application.routes.draw do
# snip
mount Sidekiq::Web, at: "/sidekiq"
end
Worker Example
app/workers/hard_worker.rb
class HardWorker
include Sidekiq::Worker
include Sidetiq::Schedulable
recurrence { daily }
def perform
# snip
end
end
起動/停止
cd /path/to/rails
RAILS_ENV=production bundle exec sidekiq -C config/sidekiq.yml
kill -QUIT `cat tmp/pids/sidekiq.pid`