Rails: Starting Sidekiq on Heroku
Solution 1
No you do not need any config with Heroku for Sidekiq, just add the RedisToGo plugin and you're on. Do not forget to attribute at least 1 worker to your app in your Heroku config.
Here is my default Procfile:
web: bundle exec thin start -p $PORT
worker: bundle exec sidekiq -c 5 -v
Solution 2
It's worth checking if the sidekiq process is really started with this command:
heroku ps
If there's no worker, then you might need to run this command:
heroku ps:scale worker+1
It turns out that there's a bug in the web UI in that some team members were not allowed to increase the number of workers from 0 to 1, even though the UI seemed to show that!
Solution 3
Starting with sidekiq version 3.0 there is an additional step, run heroku config:set REDIS_PROVIDER=REDISTOGO_URL
in the console.
Here is the process I used for Rails 4:
In the console:
heroku addons:create redistogo
heroku config:set REDIS_PROVIDER=REDISTOGO_URL
In my Procfile
I added:
worker: bundle exec sidekiq
In my gemfile.rb
I added:
gem 'redis'
I added the following file, config/initializers/redis.rb
:
uri = ENV["REDISTOGO_URL"] || "redis://localhost:6379/"
REDIS = Redis.new(:url => uri)
Here is the link to the sidekiq docs.
Solution 4
Complementing gdurelle answer:
You do need some config with Heroku for Sidekiq:
1) Have the Sidekiq and Redis gems installed (in gemfile and bundled), in my case:
Gemfile
gem 'redis', '~> 3.1'
gem 'sidekiq', '~> 2.7', '>= 2.7.1'
2) Add a worker, if you don't have any workers created locally I suggest you create at least one, just in case, use this:
rails g sidekiq:worker Hard # will create app/workers/hard_worker.rb
should create this:
app/workers/hard_worker.rb
class HardWorker
include Sidekiq::Worker
def perform(name, count)
# do something
end
end
3) Add the Redis add-on (in my case Heroku Redis):
heroku addons:create heroku-redis:hobby-dev
4) Add your redis.rb file, in my case:
config/initializers/redis.rb
$redis = Redis.new(url: ENV["REDIS_URL"])
5) Add Procfile or config/sidekiq.yml or both, here are mine:
Procfile
worker: bundle exec sidekiq -c 1 -q default -q mailers
which you can create easier by pasting this in your terminal
echo "worker: bundle exec sidekiq -c 1 -q default -q mailers" > Procfile
config/sidekiq.yml
:concurrency: 1
:queues:
- [mailers, 7]
- [default, 5]
6) Most important part go here: and turn on the switch for your worker, click on the pencil and then turn on the missing switch. Things should be working fine now, have a great day!
Solution 5
What I found out is that you have to scale process manually like so:
heroku ps:scale worker+1
Makes no sense since my Procfile said:
web: bundle exec....
worker: bundle exec sidekiq
...and one would've expectd Heroku to start the worker automatically. In the end I didn't have to scale the web process...
Also, you might have problems with this line: worker: bundle exec sidekiq
Add flags for concurency:
worker: bundle exec sidekiq -c 5 -v
Greg Rogers
Updated on July 09, 2022Comments
-
Greg Rogers almost 2 years
I'm having a problem getting Sidekiq up and running on my Heroku deployed Rails app. I have my app working fine in development (and on Heroku without Sidekiq).
I created a Procfile with:
worker: bundle exec sidekiq
If I run
heroku ps
, the only process I see isweb.1
.Should I see one for Sidekiq?
I do get an error:
Redis::CannotConnectError (Error connecting to Redis on localhost:6379)
in my Heroku logs.UPDATE: Found I probably needed
heroku addons:add redistogo
. Still not working. I feel I'm missing some basic configuration.Is there something I need to do to get Redis up and running for my Heroku app?
I've been using Redis/Sidekiq for about a day, so this is new to me.
Thanks!
Greg
-
Greg Rogers over 11 yearsYeah... it was the missing worker that was the last hangup for me. Thank you for the response! As an aside, why do you use 'thin'? Thanks!
-
gdurelle over 11 yearsold project, i'm gonna change for unicorn. if the answer help you click on the '^' arrow vote ;) ++
-
Uri Klar about 10 yearsCan you please explain the -c 5 -v options?
-
gdurelle almost 10 yearsc : concurrency, v: verbose, p: port. You should read the documentation. really.
-
Mark Gaensicke almost 10 yearsrun
bundle exec sidekiq -?
to see a list of options with explanations -
Andrew Kostka over 9 years@gdurelle The actual documentation doesn't show this in the deploy section. The documentation in general is very segmented, and it's easy to miss information.
-
Clam over 9 yearsI can only access the options help via
bundle exec sidekiq -h
Not sure if anybody has any further references to how to determine concurrency settings. -
Ryan Crews over 8 yearsthis. this was the answer to four hours of "why?!?!1!?1?!?!". thank you. (in fairness, I also needed to add the "worker: bundle exec sidekiq -c 5 -v", but you know, I did that four hours)
-
Terra Ashley about 8 yearsEdit #1 is no longer accurate.
-
tambakoo over 5 years@gdurelle what does the
-c 5 -v
do ? -
gdurelle over 5 years@tambakoo Question already asked in comments above. This question is quite all maybe it has changed since : c is concurrency and v is verbose.
-
mutantkeyboard about 4 yearsI've had exactly the same problem with
Heroku Redis
instance. Couldn't turn on the switch on Heroku dashboard, so this solution worked for me. -
calyxofheld almost 4 yearsTurning on the worker switch is what did it for me, as I already had the worker defined in my Procfile. THANK YOU!
-
Jose Paez almost 4 yearsI’m glad it helped, have a great day!
-
BenKoshy almost 4 yearsfor anyone reading this: for rails 6 in 2020 heroku recommends using puma.
-
Francisco Quintero about 3 yearsGosh, I was looking like a mad man why Sidekiq wasn't running and the switch was off all the time. Thanks!
-
Jose Paez about 3 yearsAlways glad to be of help, have a great day, happy coding!