Skip to content

Instantly share code, notes, and snippets.

@efrapp
Last active December 12, 2023 12:32
Show Gist options
  • Save efrapp/1290af276c55086a40c92a3bef9573b5 to your computer and use it in GitHub Desktop.
Save efrapp/1290af276c55086a40c92a3bef9573b5 to your computer and use it in GitHub Desktop.
Steps to setup Sidekiq on Heroku

Setup Sidekiq for Heroku

Install Heroku Redis Add-on

Option 1: Using the dashboard

Go to the Resources tab and in the Add-ons section type Heroku Redis in the search field. It will appear in the search list. Click on it and a modal will show up to install it, click in the Provision button to start the installation.

Option 2: Using the Heroku cli

Check for the add-on availability using:

$ heroku addons | grep heroku-redis

After that, install it:

$ heroku addons:create heroku-redis:hobby-dev -a <app_name>

After installed, the Redis add-on will, automaticaly, create an environment varible call REDIS_URL with the path to the Redis server.

To check the add-on status:

$ heroku addons:info redis-acute-19443

Where redis-acute-19443 is the name of the add-on. To check the add-on name, go to the Overview tab and in the Installed Add-ons section the name will appears in the Redis add-on.

Setup Sidekiq in the Rails app

Now that Redis is installed on Heroku. We need to setup Sidekiq in our Rails app to ensure that it will work on Heroku after the deploy.

Create a Procfile

In the project root create a Procfile, this file will be used by Heroku to execute the commands added it. Add this command:

worker: bundle exec sidekiq -c 2

worker could be any name and -c 2 is the number thread running concurrently, in this case 2. Push the changes to the repo and Heroku.

In the Free Dynos section under the Resource tab, will appear the worker we add in the Procfile, enable it clicking the edit button to right.

With this we have Sidekiq configured to use it on Heroku.

Useful Commands

Check the Sidekiq logs in Heroku:

heroku logs --tail --app app_name --dyno worker

Links

@yshmarov
Copy link

good!

@baranyeni
Copy link

Thank you!

@c-moyer
Copy link

c-moyer commented Jan 3, 2022

Thanks for the guide! I had an issue with Sidekiq not processing any of the jobs in my queues. There are two options for resolving this issue:

worker: bundle exec sidekiq -q your_queue_name

Or, create config/sidekiq.yml and add the following:

:queues:
  - your_queue_name

If you have set config.active_job.queue_name_prefix = 'your_prefix', then you'll have to add that to each of the options above.

@oyenmwen
Copy link

Thanks !

@sergiimostovyi
Copy link

it seems to be missing

Sidekiq.configure_server do |config|
  config.redis = {
    url: ENV["REDIS_URL"],
    ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE }
  }
end

Sidekiq.configure_client do |config|
  config.redis = {
      url: ENV["REDIS_URL"],
      ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE }
  }
end

@pperone
Copy link

pperone commented Mar 9, 2023

@sergiimostovyi where did you place that configuration?

@pperone
Copy link

pperone commented Mar 9, 2023

It seems like it goes in initializers/sidekiq.rb. I had to create the initializer manually, but that seems to have done the trick in Heroku. Also, if useful to anyone, for now Sidekiq 7 won't work with Rediscloud in Heroku, so specify gem 'sidekiq', "< 7.0" in your gemfile.

@EduardoRamosB
Copy link

Don't forget to create a worker (in addition to your application) in your App

@TBenedyk
Copy link

Heroku have discontinued their free hobby-dev plan so it's now heroku addons:create heroku-redis:mini -a <app_name>

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