-
Notifications
You must be signed in to change notification settings - Fork 307
Home
Add capistrano-sidekiq
to your Gemfile
gem 'capistrano-sidekiq' , group: :development
Load the following in your Capfile
require 'capistrano/sidekiq'
Run cap -T sidekiq
in the terminal to get a full list of the sidekiq commands:
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
Before running sidekiq in your server, you can configure the behaviour of your Sidekiq instances through capistrano-sidekiq
.
Sidekiq allows quite a wide range of command parameters at boot time. For example:
bundle exec sidekiq
--index 0
--pidfile /tmp/pids/sidekiq.pid
--environment production
--logfile /var/log/sidekiq.log
--queue notification
--concurrency 10
--daemon
Sidekiq also supports configuration files:
:concurrency: 5
:pidfile: /tmp/pids/sidekiq.pid
:queues:
- default
- [another_queue, 2]
development:
:concurrency: 5
staging:
:concurrency: 10
production:
:concurrency: 20
All these settings can be forwarded to Sidekiq from capistrano-sidekiq
, setting them in Capistrano stage files. Here the default values:
: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_roles => [:app]
:sidekiq_processes => 1
:sidekiq_concurrency => nil
Values can alternatively be loaded from a Sidekiq configuration file.
## or use config.yml file
set :sidekiq_config, "#{current_path}/config/sidekiq.yml"
or (for Capistrano 3.x)
set :sidekiq_config, -> { File.join(shared_path, 'config', 'sidekiq.yml') }
capistrano-sidekiq
adds some default hooks:
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 during deployments. Just set sidekiq_default_hooks
to false
if you don't want this to happen.
Try:
$ cap production sidekiq:start