Skip to content

Commit

Permalink
Merge pull request sidekiq#2399 from tombenner/prevent_redundant_polling
Browse files Browse the repository at this point in the history
Prevent redundant polling in the web UI
  • Loading branch information
seuros committed Jun 21, 2015
2 parents b3bea3f + 7982e4e commit bab47b5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
6 changes: 6 additions & 0 deletions test/test_web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ def perform(a, b)
assert_match /#{msg['args'][2]}/, last_response.body
end

it 'calls updatePage() once when polling' do
get '/busy?poll=true'
assert_equal 200, last_response.status
assert_equal 1, last_response.body.scan('updatePage(').count
end

it 'escape job args and error messages' do
# on /retries page
params = add_xss_retry
Expand Down
4 changes: 2 additions & 2 deletions web/views/_nav.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<span class="icon-bar"></span>
</button>
<div class="navbar-toggle collapsed navbar-livereload">
<%= erb :_poll %>
<%= erb :_poll_link %>
<% if Sidekiq::Web.app_url %>
<a class="btn btn-inverse" href="<%= Sidekiq::Web.app_url %>">Back to App</a>
<% end %>
Expand Down Expand Up @@ -54,7 +54,7 @@
<ul class="nav navbar-nav navbar-right navbar-livereload" data-navbar="static">
<li>
<div class="poll-wrapper pull-right">
<%= erb :_poll %>
<%= erb :_poll_link %>
<% if Sidekiq::Web.app_url %>
<a class="btn btn-inverse" href="<%= Sidekiq::Web.app_url %>">Back to App</a>
<% end %>
Expand Down
5 changes: 5 additions & 0 deletions web/views/_poll_js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% if current_path != '' && params[:poll] %>
<script>
updatePage('<%= root_path + current_path %>')
</script>
<% end %>
3 changes: 0 additions & 3 deletions web/views/_poll.erb → web/views/_poll_link.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<% if current_path != '' %>
<% if params[:poll] %>
<script>
updatePage('<%= root_path + current_path %>')
</script>
<a id="live-poll" class="btn btn-primary active" href="<%= root_path + current_path %>"><%= t('StopPolling') %></a>
<% else %>
<a id="live-poll" class="btn btn-primary" href="<%= root_path + current_path %>?<%= qparams(poll: true) %>"><%= t('LivePoll') %></a>
Expand Down
1 change: 1 addition & 0 deletions web/views/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
</div>
</div>
<%= erb :_footer %>
<%= erb :_poll_js %>
</body>
</html>

0 comments on commit bab47b5

Please sign in to comment.