17
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Sidekiqメモ

Last updated at Posted at 2014-08-04

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`
17
15
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
17
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?