Skip to content

Instantly share code, notes, and snippets.

@efrapp
Last active October 30, 2024 19:54
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

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

@davidauza-engineer
Copy link

Thanks!

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