Search code examples
rubysinatrasidekiq

How can I use sidekiq monitoring with a Sinatra app?


My routes file:

require 'sinatra'
require 'sidekiq'
require 'sidekiq/web'
require 'sequel'

get '/' do
   # Some stuff
end

get '/sidekiq' do
    run Sidekiq::Web
end

Going to http://localhost:4567/sidekiq:

NoMethodError at /sidekiq
undefined method `run' for #<Sinatra::Application:0x007f670d2123b8>

I am using bundle exec sidekiq -r ./workers/gyf_downloader.rb to start Sidekiq first and then bundle exec ruby routes.rb to start the Sinatra app.

Any suggestions on how I can get this working?


I have already fixed the following error:

Internal Server Error

undefined method `join' for #<String:0x007fa504414c08>
WEBrick/1.3.1 (Ruby/2.2.1/2015-02-26) at localhost:4567

by using gem 'sinatra', git: '[email protected]:sinatra/sinatra.git' in my gemfile as per Mike Perham's answer below saying to check out this Sinatra issue on github.


Solution

  • Add the following code to config.ru. Firstly define path to your app, then sidekiq. Next you should add the Sidekiq configuration and path map routes.

    # config.ru
    require './app' 
    require 'sidekiq'
    require 'sidekiq/web'
    
    Sidekiq.configure_client do |config|
      config.redis = { url: "redis://#{ENV['REDIS_HOST']}:#{ENV['REDIS_PORT']}" }
    end
    
    run Rack::URLMap.new('/' => App, '/sidekiq' => Sidekiq::Web)