Using Sidekiq with Procfile and Capistrano (example)

Posted over 1 year ago. Visible to the public.

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:
      invoke('opscomplete:supervisor:signal_procs', 'TSTP', 'sidekiq')

  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:
      invoke('opscomplete:supervisor:signal_procs', 'TTIN', 'sidekiq')

  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:
      invoke('opscomplete:supervisor:signal_procs', 'TERM', 'sidekiq')

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
Last edit
2 months ago
Moritz Kraus
Source code in this card is licensed under the MIT License.
Posted by Kim Klotz to opscomplete (2021-11-22 09:39)