Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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}
@jeregrine
Copy link

jeregrine commented Sep 5, 2013

Whats the best way to include your models in with the workers?

@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

jeregrine commented Apr 23, 2014

@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