Skip to content

Instantly share code, notes, and snippets.

@elijahmurray
Forked from subelsky/puma_rails_heroku.rb
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elijahmurray/552b69350e81acab5ec2 to your computer and use it in GitHub Desktop.
Save elijahmurray/552b69350e81acab5ec2 to your computer and use it in GitHub Desktop.
Gist to get sidekiq up and running on heroku with puma.
# Gemfile
gem "puma"
gem 'sidekiq', '~> 2.2.1'
# gem 'autoscaler'
# Procfile
web: bundle exec puma -p $PORT -e $RACK_ENV
# add to config block config/environments/production.rb
# This is becoming deprecated and needs to be updated.
config.threadsafe!
# Add redis to heroku
heroku addons:add redistogo
#https://addons.heroku.com/redistogo#nano
# Actual worker.
# Don't use i_vars (@id). Needs to be threadsafe and should look up for speed, safety.
class MyWorker
include Sidekiq::Worker
def perform(id)
puts object = Model.find(id)
end
end
# Call long job in a view, controller or model
MixpanelWorker.perform_async(@object)
#
# Local testing
# start redis, server, and sidekiq
redis-server /usr/local/etc/redis.conf
bundle exec rails server
bundle exec sidekiq
# get rid of NewRelic after_fork code, if you were doing this:
# http://support.newrelic.com/kb/troubleshooting/unicorn-no-data
# and get rid of config/unicorn.rb if you were using that
# if you use NewRelic, set your NEWRELIC_DISPATCHER environment variable on heroku, per
# https://github.com/puma/puma/issues/128 - may not be needed for future releases of Puma
heroku config:add NEWRELIC_DISPATCHER=Puma
# For autoscaling up dynos on heroku (cost effective), checkout this guide starting with the the
# Adding the autoscaler part
http://manuel.manuelles.nl/blog/2012/11/13/scalable-heroku-worker-for-sidekiq/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment