Using Sidekiq with Procfile and Capistrano (example)

Here is an example configuration for using Sidekiq with our Procfile support and Capistrano.

Sidekiq specific steps in lib/capistrano/tasks/sidekiq.rake. Please make sure the roles meet your needs:

# frozen_string_literal: true

namespace :sidekiq do
  desc 'quiet all sidekiq processes so they stop accepting new jobs'
  task :quiet do
    on roles :cron do
      # The TSTP signal tells sidekiq to quiet all workers.
      # see: https://github.com/mperham/sidekiq/wiki/Signals#tstp
      invoke('opscomplete:supervisor:signal_procs', 'TSTP', 'sidekiq')
    end
  end

  desc 'print a backtrace for all sidekiq threads to the logfile'
  task :trace do
    on roles :cron do
      # The TTIN signal tells sidekiq to print a backtrace for all threads to the logfile.
      # see: https://github.com/mperham/sidekiq/wiki/Signals#ttin
      invoke('opscomplete:supervisor:signal_procs', 'TTIN', 'sidekiq')
    end
  end

  desc 'shuts down all sidekiq processes within the configured timout'
  task :term do
    on roles :cron do
      # The TERM signal tells sidekiq to kill quiet all processes for the configured timout time and then kill them.
      # see: https://github.com/mperham/sidekiq/wiki/Signals#term
      invoke('opscomplete:supervisor:signal_procs', 'TERM', 'sidekiq')
    end
  end
end

Sidekiq/Supervisor specific hooks for config/deploy.rb:

# Update and Restart supervisor config
after 'deploy:starting', 'sidekiq:quiet'
after 'deploy:updating', 'opscomplete:supervisor:gen_config'
after 'deploy:published', 'opscomplete:supervisor:restart_procs'

# Terminate sidekiq quiet processes (new processes get started by supervisor)
after 'deploy:failed', 'sidekiq:term'

You Procfile should include e.g. this command for running sidekiq:

sidekiq: bundle exec sidekiq --config config/sidekiq.yml
Kim Klotz Over 2 years ago