LoginSignup
24
24

More than 5 years have passed since last update.

Heroku 上で Rails に非同期処理の sidekiq を導入する

Last updated at Posted at 2013-04-17

基本セットアップ

Gemfile

gem 'sidekiq'

アプリ上では

obj.foo_process

obj.delay.foo_process

という感じで実装すれば遅延処理になる

管理Webviewを設定

管理WebViewにはBasic認証をかける

routes.rb

require 'sidekiq/web'

Sidekiq::Web.use Rack::Auth::Basic do |username, password|
  username == 'basicuser' && password == 'basicpass'
end
mount Sidekiq::Web => '/sidekiq'

Heroku上ではCSSの読み込みが失敗するのを修正

config/envirments/production.rb

config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'

開発環境等では非同期にしない

config/initializer/sidekiq.rb

unless Rails.env.production?
  require 'sidekiq/testing/inline'
end

Heroku上でRedisを入れる

heroku addons:add redistogo:nano

ローカル環境

Macでのセットアップ

brew install redis
24
24
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
24