7
4

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.

Capistrano-sidekiqのすすめ

Posted at

Introduction

かなり前だが、弊アプリケーションにsidekiqを導入して、gem capistrano-sidekiqでデプロイ時にプロセスの起動・再起動をしていたが、ある環境だけsidekiqのプロセスを立ち上げたくない場合があったので、備忘録として書き留めておきたいと思います。

Dependencies

Gemfile.lock
sidekiq (5.0.4)
sidekiq-pro (3.7.1)
capistrano (3.6.1)
capistrano-sidekiq (0.10.0)

How to use

Capfile
require "capistrano/sidekiq"

基本的にCapfileにrequireしてあげるだけで、sidekiq:add_default_hooksタスクが走ります。

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

これは、
capistrano-sidekiq/sidekiq.rake at master · seuros/capistrano-sidekiq · GitHub

capistrano-sidekiq/lib/capistrano/tasks/sidekiq.rake
set :sidekiq_default_hooks, true

がデフォルトでtrueになっているためです。

なので、特定の環境でsidekiq:add_default_hooksタスクを実行しないようにするには、

config/deploy/**.rb
set :sidekiq_default_hooks, false

もしくは、プロセスがある場合は落とす処理を書いてあげる場合は、

config/deploy.rb
if fetch(:stage) == :hoge
  set :sidekiq_default_hooks, false
  after 'deploy:starting', 'sidekiq:quiet'
  after 'deploy:updated', 'sidekiq:stop'
end

で、環境ごとの制御ができると思います。

others

$ bundle exec cap -T sidekiq
cap sidekiq:quiet            # Quiet sidekiq (stop processing new tasks)
cap sidekiq:respawn          # Respawn missing sidekiq processes
cap sidekiq:restart          # Restart sidekiq
cap sidekiq:rolling_restart  # Rolling-restart sidekiq
cap sidekiq:start            # Start sidekiq
cap sidekiq:stop             # Stop sidekiq

については、

capistrano-sidekiq/lib/capistrano/tasks/sidekiq.rake
の各タスクのコードを見た方がわかりやすいので説明は省略します。

Reference

gem capistrano-sidekiq
gem capistrano-sidekiq wiki

7
4
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
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?