Skip to content

Instantly share code, notes, and snippets.

@john-hamnavoe
Last active January 5, 2023 16:29
Show Gist options
  • Save john-hamnavoe/bcd5b9753fac0d104de87103f1b80211 to your computer and use it in GitHub Desktop.
Save john-hamnavoe/bcd5b9753fac0d104de87103f1b80211 to your computer and use it in GitHub Desktop.
Basic Steps to Add Sidekiq to Rails 7 App

Gemfile

gem "sidekiq", "~> 6.2"
gem "sidekiq-failures"

Update config/application.rb

 class Application < Rails::Application
    config.active_job.queue_adapter = :sidekiq
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 7.0

Update config/puma.rb and config/database.yml respectively:

max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 10 }
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 10 } %>

This prevents sidekiq active record ActiveRecord::ConnectionTimeoutError errors.

Update Procfile.dev

Add worker
worker: bundle exec sidekiq

Update config\routes.rb

Require sidekiq before routes.draw and add route for admin user (ignore admin if user table does not have admin column).

require 'sidekiq/web'

Rails.application.routes.draw do
  authenticate :user, lambda { |u| u.admin? } do
    mount Sidekiq::Web => '/sidekiq'
  end
 
  # rest of routes...

Hatchbox

If using hatchbox add new process worker

bundle exec sidekiq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment