diff --git a/lib/sidekiq/web.rb b/lib/sidekiq/web.rb index e253178d..2e72c9d7 100644 --- a/lib/sidekiq/web.rb +++ b/lib/sidekiq/web.rb @@ -37,17 +37,34 @@ module Sidekiq helpers do def workers - Sidekiq.redis.smembers('workers') + @workers ||= begin + Sidekiq.redis.smembers('workers').map do |w| + msg = Sidekiq.redis.get("worker:#{w}") + msg = MultiJson.decode(msg) if msg + [w, msg] + end.sort { |x| x[1] ? -1 : 1 } + end end + def queues - Sidekiq.redis.smembers('queues') + Sidekiq.redis.smembers('queues').map do |q| + [q, Sidekiq.redis.llen("queue:#{q}") || 0] + end.sort { |x,y| x[1] <=> y[1] } end + def location Sidekiq.redis.client.location end + def root_path "#{env['SCRIPT_NAME']}/" end + + def status + return 'down' if workers.size == 0 + return 'idle' if workers.size > 0 && workers.map { |x| x[1] }.compact.size == 0 + return 'active' + end end get "/" do @@ -56,7 +73,7 @@ module Sidekiq get "/queues/:name" do @name = params[:name] - @messages = Sidekiq.redis.lrange("queue:#{params[:name]}", 0, 10).map { |str| MultiJson.decode(str) } + @messages = Sidekiq.redis.lrange("queue:#{@name}", 0, 10).map { |str| MultiJson.decode(str) } slim :queue end end diff --git a/myapp/app/controllers/work_controller.rb b/myapp/app/controllers/work_controller.rb index 49363712..4a9113c2 100644 --- a/myapp/app/controllers/work_controller.rb +++ b/myapp/app/controllers/work_controller.rb @@ -13,7 +13,7 @@ class WorkController < ApplicationController end def long - 10.times do |x| + 50.times do |x| HardWorker.perform_async('bob', 10, x) end render :text => 'enqueued' diff --git a/web/views/index.slim b/web/views/index.slim index 18ae45b6..3384f229 100644 --- a/web/views/index.slim +++ b/web/views/index.slim @@ -1,5 +1,6 @@ -header - h1 Overview + +.hero-unit + h1 Sidekiq is #{status} .tabbable ul.nav.nav-tabs @@ -12,16 +13,26 @@ header table class="table table-striped table-bordered" tr th Queue - - queues.each do |queue| + th Size + - queues.each do |(queue, size)| tr td a href="queues/#{queue}" #{queue} + td= size #workers.tab-pane table class="table table-striped table-bordered" tr - th Workers - - workers.each do |worker| + th Worker + th Queue + th Class + th Arguments + - workers.each do |(worker, msg)| tr - td - a href="workers/#{worker}" #{worker} + td= worker + - if msg + td= msg['queue'] + td= msg['payload']['class'] + td= msg['payload']['args'].inspect[0..100] + - else + td colspan=3 Idle diff --git a/web/views/layout.slim b/web/views/layout.slim index 298ec1ad..a5af4add 100644 --- a/web/views/layout.slim +++ b/web/views/layout.slim @@ -7,13 +7,16 @@ html .navbar.navbar-fixed-top .navbar-inner .container - a class='brand' href='#{{root_path}}' + a.brand href='#{{root_path}}' | Sidekiq - ul class='nav' + ul.nav li a href='#{{root_path}}' Home - li.pull-right + ul.nav.pull-right + li a Redis: #{location} + li + a #{Time.now.utc} .container == yield