Skip to content
tehPlayer edited this page Sep 17, 2014 · 12 revisions

Welcome to the capistrano-sidekiq

Install with Rails

Add capistrano-sidekiq for your rails app

gem 'capistrano-sidekiq' , group: :development

Then run cap -vT in terminal you can get the sidekiq command list:

cap sidekiq:quiet                  # Quiet sidekiq (stop processing new tasks)
cap sidekiq:respawn                # Respawn missing sidekiq proccesses
cap sidekiq:restart                # Restart sidekiq
cap sidekiq:rolling_restart        # Rolling-restart sidekiq
cap sidekiq:start                  # Start sidekiq
cap sidekiq:stop                   # Stop sidekiq

Config with capistrano-sidekiq

Before run sidekiq in your server, you should to know how to set the configs with capistrano-sidekiq.

If you have used sidekiq before, of course you have. :) You can through command parameters to start sidekiq like this:

bundle exec sidekiq --index 0 --pidfile /home/lanvige/apps/demoapp/shared/tmp/pids/sidekiq.pid --environment production --logfile /home/lanvige/apps/demoapp/shared/log/sidekiq.log --queue notification --concurrency 10 --daemon

or start sidekiq with a config file

:concurrency: 5
:pidfile: tmp/pids/sidekiq.pid

:queues:
    - default
    - [myqueue, 2]

development:
  :concurrency: 5
staging:
  :concurrency: 10
production:
  :concurrency: 20

You also can use the same two methods to start sidekiq on server.

capistrano-sidekiq show these property to set in Capistrano stage file. Default value at the end of line.

:sidekiq_default_hooks =>  true
:sidekiq_pid =>  File.join(shared_path, 'tmp', 'pids', 'sidekiq.pid')
:sidekiq_env =>  fetch(:rack_env, fetch(:rails_env, fetch(:stage)))
:sidekiq_log =>  File.join(shared_path, 'log', 'sidekiq.log')
:sidekiq_options =>  nil
:sidekiq_require => nil
:sidekiq_tag => nil
:sidekiq_config => nil
:sidekiq_queue => nil
:sidekiq_timeout =>  10
:sidekiq_role =>  :app
:sidekiq_processes =>  1
:sidekiq_concurrency => nil

It's the demo for set multiple queue and concurrency value.

## sidekiq
set :sidekiq_concurrency, 10
set :sidekiq_queue, ['client_sms,2', 'client_emails,5', 'default,3', 'foo']

or get the value from config file

## or use config.yml file
set :sidekiq_config, "#{current_path}/config/sidekiq.yml"

or

set :sidekiq_config, -> { File.join(shared_path, 'config', 'sidekiq.yml') }
sidekiq_default_hooks

capistrano-sidekiq add default hooks for capistrano rails as below:

task :add_default_hooks do
  after 'deploy:starting', 'sidekiq:quiet'
  after 'deploy:updated', 'sidekiq:stop'
  after 'deploy:reverted', 'sidekiq:stop'
  after 'deploy:published', 'sidekiq:start'
end

Sidekiq will start or stop automatically with Rails deploy. Just set sidekiq_default_hooks as false if you don't want it.

Run

Try:

$ cap production sidekiq:start

hahahaha!

Other

Remind to set pty false in Capistrano 3.x to start sidekiq normally. https://github.com/seuros/capistrano-sidekiq/issues/23

Clone this wiki locally