# Make sure you have Sinatra installed, then start sidekiq with # ./bin/sidekiq -r ./examples/sinkiq.rb # Simply run Sinatra with # ruby examples/sinkiq.rb # and then browse to http://localhost:4567 # require 'sinatra' require 'sidekiq' require 'redis' $redis = Redis.new class SinatraWorker include Sidekiq::Worker def perform(msg="lulz you forgot a msg!") $redis.lpush("sinkiq-example-messages", msg) end end get '/' do stats = Sidekiq::Stats.new @failed = stats.failed @processed = stats.processed @messages = $redis.lrange('sinkiq-example-messages', 0, -1) erb :index end post '/msg' do SinatraWorker.perform_async params[:msg] redirect to('/') end __END__ @@ layout Sinatra + Sidekiq <%= yield %> @@ index

Sinatra + Sidekiq Example

Failed: <%= @failed %>

Processed: <%= @processed %>

Refresh page

Messages

<% @messages.each do |msg| %>

<%= msg %>

<% end %>