Skip to content

Instantly share code, notes, and snippets.

@passcod
Created September 20, 2012 05:15
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save passcod/3754086 to your computer and use it in GitHub Desktop.
Save passcod/3754086 to your computer and use it in GitHub Desktop.
Padrino + Sidekiq = ♥
# 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')
# ...
# ...
gem 'sidekiq'
# ...
# workers/hard_worker.rb
class HardWorker
include Sidekiq::Worker
def perform(name, count)
puts 'Doing hard work'
end
end
web: bundle exec thin start -p $PORT
worker: bundle exec sidekiq -r ./config/workers.rb
# app/controllers/test.rb
YourApp.controller do
get '/test' do
HardWorker.perform_async('bob', 5)
end
end
# config/workers.rb
Dir[File.expand_path('../../workers/*.rb', __FILE__)].each{|file|require file}
@kke
Copy link

kke commented Nov 5, 2013

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

@jeregrine
Copy link

@kke wouldn't your config/workers be loading up the boot and the boot loading up the workers?

@allenan
Copy link

allenan commented Sep 1, 2014

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