Created
September 20, 2012 05:15
-
-
Save passcod/3754086 to your computer and use it in GitHub Desktop.
Padrino + Sidekiq = ♥
This file contains 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) | |
# Load worker definitions | |
require File.join(PADRINO_ROOT, 'config', 'workers.rb') | |
# ... |
This file contains 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' | |
# ... |
This file contains 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) | |
puts 'Doing hard work' | |
end | |
end |
This file contains 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 thin start -p $PORT | |
worker: bundle exec sidekiq -r ./config/workers.rb |
This file contains 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 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} |
@jeregrine in config/workers.rb :
require File.expand_path('../boot.rb', __FILE__)
This way all your workers can do anything that you could do in a padrino console like access models.
@kke wouldn't your config/workers be loading up the boot and the boot loading up the workers?
In case anyone is trying to to get the sidekiq web interface running, just add the following to config.ru
# Load sidekiq web interface
require 'sidekiq/web'
map('/sidekiq') { run Sidekiq::Web }
require File.expand_path("../config/boot.rb", __FILE__)
run Padrino.application
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Whats the best way to include your models in with the workers?