diff --git a/config.ru b/config.ru new file mode 100644 index 00000000..da132110 --- /dev/null +++ b/config.ru @@ -0,0 +1,8 @@ +require 'sidekiq' + +Sidekiq.configure_client do |config| + config.redis = { :size => 1 } +end + +require 'sidekiq/web' +run Sidekiq::Web diff --git a/lib/sidekiq/web.rb b/lib/sidekiq/web.rb index 16f9a017..e253178d 100644 --- a/lib/sidekiq/web.rb +++ b/lib/sidekiq/web.rb @@ -32,11 +32,33 @@ module Sidekiq dir = File.expand_path(File.dirname(__FILE__) + "/../../web") set :views, "#{dir}/views" set :root, "#{dir}/public" + set :slim, :pretty => true use SprocketsMiddleware, :root => dir + 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 + get "/" do slim :index end + + get "/queues/:name" do + @name = params[:name] + @messages = Sidekiq.redis.lrange("queue:#{params[:name]}", 0, 10).map { |str| MultiJson.decode(str) } + slim :queue + end end end diff --git a/myapp/config/initializers/sidekiq.rb b/myapp/config/initializers/sidekiq.rb index 0e04146e..f8f7c13b 100644 --- a/myapp/config/initializers/sidekiq.rb +++ b/myapp/config/initializers/sidekiq.rb @@ -1,6 +1,6 @@ Sidekiq.configure_client do |config| - config.redis = { :namespace => 'resque', :size => 2 } + config.redis = { :size => 2 } end Sidekiq.configure_server do |config| - config.redis = { :namespace => 'resque', :size => 25 } + config.redis = { :size => 25 } end diff --git a/web/views/index.slim b/web/views/index.slim index 7276506c..18ae45b6 100644 --- a/web/views/index.slim +++ b/web/views/index.slim @@ -1,5 +1,27 @@ header - h1 Index -div class="row" - div class="span12" - | Index goes here + h1 Overview + +.tabbable + ul.nav.nav-tabs + li.active + a href="#queues" data-toggle="tab" Queues + li + a href="#workers" data-toggle="tab" Workers + .tab-content + #queues.tab-pane.active + table class="table table-striped table-bordered" + tr + th Queue + - queues.each do |queue| + tr + td + a href="queues/#{queue}" #{queue} + + #workers.tab-pane + table class="table table-striped table-bordered" + tr + th Workers + - workers.each do |worker| + tr + td + a href="workers/#{worker}" #{worker} diff --git a/web/views/layout.slim b/web/views/layout.slim index b32c07eb..298ec1ad 100644 --- a/web/views/layout.slim +++ b/web/views/layout.slim @@ -1,23 +1,21 @@ doctype html html head - link href='assets/application.css' media='screen' rel='stylesheet' type='text/css' + link href='#{{root_path}}assets/application.css' media='screen' rel='stylesheet' type='text/css' title Sidekiq body - div class="navbar navbar-fixed-top" - div class="navbar-inner" - div class="container" - a class='brand' href='' + .navbar.navbar-fixed-top + .navbar-inner + .container + a class='brand' href='#{{root_path}}' | Sidekiq ul class='nav' li - a href='' Home - - div class="container" + a href='#{{root_path}}' Home + li.pull-right + a Redis: #{location} + .container == yield - footer class="footer" - p © #{Time.now.year} Mike Perham - - script type="text/javascript" src="assets/application.js" + script type="text/javascript" src="#{{root_path}}assets/application.js" diff --git a/web/views/queue.slim b/web/views/queue.slim new file mode 100644 index 00000000..6c122030 --- /dev/null +++ b/web/views/queue.slim @@ -0,0 +1,11 @@ +header + h1 Latest messages in #{@name} + +table class="table table-striped table-bordered" + tr + th Class + th Arguments + - @messages.each do |msg| + tr + td= msg['class'] + td= msg['args'].inspect[0..100]