2012-03-04 15:58:16 -05:00
|
|
|
require 'sinatra/base'
|
|
|
|
require 'slim'
|
|
|
|
require 'sprockets'
|
|
|
|
|
|
|
|
module Sidekiq
|
|
|
|
class SprocketsMiddleware
|
|
|
|
def initialize(app, options={})
|
|
|
|
@app = app
|
|
|
|
@root = options[:root]
|
|
|
|
path = options[:path] || 'assets'
|
|
|
|
@matcher = /^\/#{path}\/*/
|
|
|
|
@environment = ::Sprockets::Environment.new(@root)
|
|
|
|
@environment.append_path 'assets/javascripts'
|
|
|
|
@environment.append_path 'assets/javascripts/vendor'
|
|
|
|
@environment.append_path 'assets/stylesheets'
|
|
|
|
@environment.append_path 'assets/stylesheets/vendor'
|
|
|
|
@environment.append_path 'assets/images'
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
2012-03-05 22:27:27 -05:00
|
|
|
# Solve the problem of people requesting /sidekiq when they need to request /sidekiq/ so
|
|
|
|
# that relative links in templates resolve correctly.
|
|
|
|
return [301, { 'Location' => "#{env['SCRIPT_NAME']}/" }, []] if env['SCRIPT_NAME'] == env['REQUEST_PATH']
|
|
|
|
|
2012-03-04 15:58:16 -05:00
|
|
|
return @app.call(env) unless @matcher =~ env["PATH_INFO"]
|
|
|
|
env['PATH_INFO'].sub!(@matcher,'')
|
|
|
|
@environment.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Web < Sinatra::Base
|
2012-03-05 22:27:27 -05:00
|
|
|
dir = File.expand_path(File.dirname(__FILE__) + "/../../web")
|
2012-03-04 15:58:16 -05:00
|
|
|
set :views, "#{dir}/views"
|
|
|
|
set :root, "#{dir}/public"
|
2012-03-05 23:53:14 -05:00
|
|
|
set :slim, :pretty => true
|
2012-03-05 22:27:27 -05:00
|
|
|
use SprocketsMiddleware, :root => dir
|
2012-03-04 15:58:16 -05:00
|
|
|
|
2012-03-05 23:53:14 -05:00
|
|
|
helpers do
|
|
|
|
def workers
|
|
|
|
Sidekiq.redis.smembers('workers')
|
|
|
|
end
|
|
|
|
def queues
|
|
|
|
Sidekiq.redis.smembers('queues')
|
|
|
|
end
|
|
|
|
def location
|
|
|
|
Sidekiq.redis.client.location
|
|
|
|
end
|
|
|
|
def root_path
|
|
|
|
"#{env['SCRIPT_NAME']}/"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-04 15:58:16 -05:00
|
|
|
get "/" do
|
|
|
|
slim :index
|
|
|
|
end
|
2012-03-05 23:53:14 -05:00
|
|
|
|
|
|
|
get "/queues/:name" do
|
|
|
|
@name = params[:name]
|
|
|
|
@messages = Sidekiq.redis.lrange("queue:#{params[:name]}", 0, 10).map { |str| MultiJson.decode(str) }
|
|
|
|
slim :queue
|
|
|
|
end
|
2012-03-04 15:58:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|