mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Merge pull request #317 from jakemack/add_polling
Added polling to the index page to monitor jobs and workers more easily
This commit is contained in:
commit
79dd455cb4
9 changed files with 83 additions and 28 deletions
|
@ -117,6 +117,10 @@ module Sidekiq
|
|||
slim :index
|
||||
end
|
||||
|
||||
get "/poll" do
|
||||
slim :poll, layout: false
|
||||
end
|
||||
|
||||
get "/queues" do
|
||||
@queues = queues
|
||||
slim :queues
|
||||
|
|
|
@ -31,6 +31,14 @@ class TestWeb < MiniTest::Unit::TestCase
|
|||
refute_match /default/, last_response.body
|
||||
end
|
||||
|
||||
it 'can display poll' do
|
||||
get '/poll'
|
||||
assert_equal 200, last_response.status
|
||||
assert_match /hero-unit/, last_response.body
|
||||
assert_match /workers/, last_response.body
|
||||
refute_match /navbar/, last_response.body
|
||||
end
|
||||
|
||||
it 'can display queues' do
|
||||
assert Sidekiq::Client.push('queue' => :foo, 'class' => WebWorker, 'args' => [1, 3])
|
||||
|
||||
|
@ -115,26 +123,26 @@ class TestWeb < MiniTest::Unit::TestCase
|
|||
assert_equal 200, last_response.status
|
||||
assert_match /HardWorker/, last_response.body
|
||||
end
|
||||
|
||||
|
||||
it 'can delete a single retry' do
|
||||
_, score = add_retry
|
||||
|
||||
post "/retries/#{score}", 'delete' => 'Delete'
|
||||
assert_equal 302, last_response.status
|
||||
assert_equal 'http://example.org/retries', last_response.header['Location']
|
||||
|
||||
|
||||
get "/retries"
|
||||
assert_equal 200, last_response.status
|
||||
refute_match /#{score}/, last_response.body
|
||||
end
|
||||
|
||||
|
||||
it 'can retry a single retry now' do
|
||||
msg, score = add_retry
|
||||
|
||||
post "/retries/#{score}", 'retry' => 'Retry'
|
||||
assert_equal 302, last_response.status
|
||||
assert_equal 'http://example.org/retries', last_response.header['Location']
|
||||
|
||||
|
||||
get '/queues/default'
|
||||
assert_equal 200, last_response.status
|
||||
assert_match /#{msg['args'][2]}/, last_response.body
|
||||
|
|
|
@ -18,3 +18,32 @@ $(function() {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(function() {
|
||||
$('a[name=poll]').data('polling', false);
|
||||
|
||||
$('a[name=poll]').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
var pollLink = $(this);
|
||||
if (pollLink.data('polling')) {
|
||||
clearInterval(pollLink.data('interval'));
|
||||
pollLink.text('Live Poll');
|
||||
$('.poll-status').text('');
|
||||
}
|
||||
else {
|
||||
var href = pollLink.attr('href');
|
||||
pollLink.data('interval', setInterval(function() {
|
||||
$.get(href, function(data) {
|
||||
var responseHtml = $(data);
|
||||
$('.hero-unit').replaceWith(responseHtml.find('.hero-unit'));
|
||||
$('.workers').replaceWith(responseHtml.find('.workers'));
|
||||
});
|
||||
var currentTime = new Date();
|
||||
$('.poll-status').text('Last polled at: ' + currentTime.getHours() + ':' + currentTime.getMinutes() + ':' + currentTime.getSeconds());
|
||||
}, 2000));
|
||||
$('.poll-status').text('Starting to poll...');
|
||||
pollLink.text('Stop Polling');
|
||||
}
|
||||
pollLink.data('polling', !pollLink.data('polling'));
|
||||
})
|
||||
});
|
||||
|
|
|
@ -20,3 +20,7 @@ code {
|
|||
.hero-unit {
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.poll-status {
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
|
8
web/views/_summary.slim
Normal file
8
web/views/_summary.slim
Normal file
|
@ -0,0 +1,8 @@
|
|||
.hero-unit
|
||||
h1 Sidekiq is #{current_status}
|
||||
p Processed: #{processed}
|
||||
p Failed: #{failed}
|
||||
p Busy Workers: #{workers.size}
|
||||
p Scheduled: #{zcard('schedule')}
|
||||
p Retries Pending: #{zcard('retry')}
|
||||
p Queue Backlog: #{backlog}
|
14
web/views/_workers.slim
Normal file
14
web/views/_workers.slim
Normal file
|
@ -0,0 +1,14 @@
|
|||
table class="table table-striped table-bordered workers"
|
||||
tr
|
||||
th Worker
|
||||
th Queue
|
||||
th Class
|
||||
th Arguments
|
||||
th Started
|
||||
- workers.each do |(worker, msg)|
|
||||
tr
|
||||
td= worker
|
||||
td= msg['queue']
|
||||
td= msg['payload']['class']
|
||||
td= msg['payload']['args'].inspect[0..100]
|
||||
td== relative_time(Time.parse(msg['run_at']))
|
|
@ -1,25 +1,10 @@
|
|||
.hero-unit
|
||||
h1 Sidekiq is #{current_status}
|
||||
p Processed: #{processed}
|
||||
p Failed: #{failed}
|
||||
p Busy Workers: #{workers.size}
|
||||
p Scheduled: #{zcard('schedule')}
|
||||
p Retries Pending: #{zcard('retry')}
|
||||
p Queue Backlog: #{backlog}
|
||||
== slim :_summary
|
||||
|
||||
.poll
|
||||
a*{name: 'poll'} href='#{{root_path}}poll' Live Poll
|
||||
span class="poll-status"
|
||||
|
||||
== slim :_workers
|
||||
|
||||
table class="table table-striped table-bordered"
|
||||
tr
|
||||
th Worker
|
||||
th Queue
|
||||
th Class
|
||||
th Arguments
|
||||
th Started
|
||||
- workers.each do |(worker, msg)|
|
||||
tr
|
||||
td= worker
|
||||
td= msg['queue']
|
||||
td= msg['payload']['class']
|
||||
td= msg['payload']['args'].inspect[0..100]
|
||||
td== relative_time(Time.parse(msg['run_at']))
|
||||
form action="#{root_path}reset" method="post"
|
||||
button.btn type="submit" title="If you kill -9 Sidekiq, this table can fill up with old data." Clear worker list
|
||||
button.btn type="submit" title="If you kill -9 Sidekiq, this table can fill up with old data." Clear worker list
|
||||
|
|
|
@ -13,7 +13,7 @@ html
|
|||
span.icon-bar
|
||||
a.brand href='#{{root_path}}'
|
||||
| Sidekiq
|
||||
div.nav-collapse
|
||||
div.nav-collapse
|
||||
ul.nav
|
||||
li
|
||||
a href='#{{root_path}}' Home
|
||||
|
|
3
web/views/poll.slim
Normal file
3
web/views/poll.slim
Normal file
|
@ -0,0 +1,3 @@
|
|||
div
|
||||
== slim :_summary
|
||||
== slim :_workers
|
Loading…
Add table
Reference in a new issue