-
-
Save paracycle/5591185 to your computer and use it in GitHub Desktop.
How to use Sidekiq with Padrino on Heroku. This config enables you to run sidekiq inside your "web" dyno (See https://coderwall.com/p/fprnhg for details)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/boot.rb | |
# ... | |
# Load our dependencies | |
require 'rubygems' unless defined?(Gem) | |
require 'bundler/setup' | |
Bundler.require(:default, PADRINO_ENV) | |
Padrino.before_load do | |
# Load worker definitions | |
require File.join(PADRINO_ROOT, 'config', 'workers.rb') | |
end | |
# ... | |
Padrino.after_load do | |
# Sidekiq should log to our main log file. | |
Sidekiq.logger = Padrino.logger | |
# Make sure that all mailers are loaded. Without this I was having problems delivering emails from workers. | |
Padrino.require_dependencies("#{Padrino.root}/app/mailers/*.rb") | |
end | |
# ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env rackup | |
# encoding: utf-8 | |
require File.expand_path("../config/boot.rb", __FILE__) | |
require 'sidekiq/web' | |
map('/sidekiq') { run Sidekiq::Web } | |
run Padrino.application |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
gem 'sidekiq' | |
gem 'slim' | |
gem 'unicorn' | |
# ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# workers/hard_worker.rb | |
class HardWorker | |
include Sidekiq::Worker | |
def perform(name, count) | |
MyApp::App.deliver(:mailer_name, :email_name, name, count) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See http://manuel.manuelles.nl/blog/2012/11/13/sidekiq-on-heroku-with-redistogo-nano/ | |
:concurrency: 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/test.rb | |
YourApp.controller do | |
get '/test' do | |
HardWorker.perform_async('bob', 5) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sidekiq' | |
worker_processes 3 | |
before_fork do |server, worker| | |
# Spawn Sidekiq worker inside the current process. | |
@worker_pid = spawn('bundle exec sidekiq -C ./config/sidekiq.yml -r ./config/boot.rb') | |
t = Thread.new { | |
Process.wait(@worker_pid) | |
puts "Worker died. Bouncing unicorn." | |
Process.kill 'QUIT', Process.pid | |
} | |
# Just in case | |
t.abort_on_exception = true | |
end | |
after_fork do |server, worker| | |
Sidekiq.configure_client do |config| | |
config.redis = { :size => 1 } # Limit the client size, see http://manuel.manuelles.nl/blog/2012/11/13/sidekiq-on-heroku-with-redistogo-nano/ | |
end | |
Sidekiq.configure_server do |config| | |
config.redis = { :size => 2 } # Limit the server size, see http://manuel.manuelles.nl/blog/2012/11/13/sidekiq-on-heroku-with-redistogo-nano/ | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/workers.rb | |
Dir[File.expand_path('../../workers/*.rb', __FILE__)].each{|file|require file} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment