mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Refactor UI to include worker status and overall status
This commit is contained in:
parent
05a8ab4d5a
commit
8daf4d7301
4 changed files with 45 additions and 14 deletions
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue