mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Add pagination to Web UI
This commit is contained in:
parent
94a8993d65
commit
67387a940d
9 changed files with 71 additions and 22 deletions
|
@ -4,6 +4,7 @@ HEAD
|
|||
- Tune Celluloid to no longer run message processing within a Fiber.
|
||||
This gives us a full Thread stack and also lowers Sidekiq's memory
|
||||
usage.
|
||||
- Add pagination for lists within the Web UI [#253]
|
||||
|
||||
2.0.3
|
||||
-----------
|
||||
|
|
2
Gemfile
2
Gemfile
|
@ -5,7 +5,7 @@ gem 'celluloid'
|
|||
gem 'slim'
|
||||
gem 'sprockets'
|
||||
gem 'sass'
|
||||
gem 'rails', '3.2.3'
|
||||
gem 'rails', '3.2.6'
|
||||
gem 'sqlite3'
|
||||
|
||||
group :test do
|
||||
|
|
31
lib/sidekiq/paginator.rb
Normal file
31
lib/sidekiq/paginator.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
module Sidekiq
|
||||
module Paginator
|
||||
def page(key, pageidx=1, page_size=25)
|
||||
current_page = pageidx.to_i < 1 ? 1 : pageidx.to_i
|
||||
pageidx = current_page - 1
|
||||
total_size = 0
|
||||
items = []
|
||||
starting = pageidx * page_size
|
||||
ending = starting + page_size - 1
|
||||
|
||||
Sidekiq.redis do |conn|
|
||||
type = conn.type(key)
|
||||
|
||||
case type
|
||||
when 'zset'
|
||||
total_size = conn.zcard(key)
|
||||
items = conn.zrange(key, starting, ending, :with_scores => true)
|
||||
when 'list'
|
||||
total_size = conn.llen(key)
|
||||
items = conn.lrange(key, starting, ending)
|
||||
when 'none'
|
||||
return [1, 0, []]
|
||||
else
|
||||
raise "can't page a #{type}"
|
||||
end
|
||||
end
|
||||
|
||||
[current_page, total_size, items]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,8 @@
|
|||
require 'sinatra/base'
|
||||
require 'slim'
|
||||
require 'sprockets'
|
||||
require 'sidekiq/paginator'
|
||||
|
||||
module Sidekiq
|
||||
class SprocketsMiddleware
|
||||
def initialize(app, options={})
|
||||
|
@ -28,6 +30,8 @@ module Sidekiq
|
|||
end
|
||||
|
||||
class Web < Sinatra::Base
|
||||
include Sidekiq::Paginator
|
||||
|
||||
dir = File.expand_path(File.dirname(__FILE__) + "/../../web")
|
||||
set :views, "#{dir}/views"
|
||||
set :root, "#{dir}/public"
|
||||
|
@ -68,21 +72,6 @@ module Sidekiq
|
|||
Sidekiq.redis { |conn| conn.zcard(name) }
|
||||
end
|
||||
|
||||
def retries(count=50)
|
||||
zcontents('retry', count)
|
||||
end
|
||||
|
||||
def scheduled(count=50)
|
||||
zcontents('schedule', count)
|
||||
end
|
||||
|
||||
def zcontents(name, count)
|
||||
Sidekiq.redis do |conn|
|
||||
results = conn.zrange(name, 0, count, :withscores => true)
|
||||
results.map { |msg, score| [Sidekiq.load_json(msg), score] }
|
||||
end
|
||||
end
|
||||
|
||||
def queues
|
||||
@queues ||= Sidekiq.redis do |conn|
|
||||
conn.smembers('queues').map do |q|
|
||||
|
@ -135,9 +124,10 @@ module Sidekiq
|
|||
|
||||
get "/queues/:name" do
|
||||
halt 404 unless params[:name]
|
||||
count = (params[:count] || 10).to_i
|
||||
@count = (params[:count] || 25).to_i
|
||||
@name = params[:name]
|
||||
@messages = Sidekiq.redis {|conn| conn.lrange("queue:#{@name}", 0, count) }.map { |str| Sidekiq.load_json(str) }
|
||||
(@current_page, @total_size, @messages) = page("queue:#{@name}", params[:page], @count)
|
||||
@messages = @messages.map {|msg| Sidekiq.load_json(msg) }
|
||||
slim :queue
|
||||
end
|
||||
|
||||
|
@ -163,12 +153,16 @@ module Sidekiq
|
|||
end
|
||||
|
||||
get '/retries' do
|
||||
@retries = retries
|
||||
@count = (params[:count] || 25).to_i
|
||||
(@current_page, @total_size, @retries) = page("retry", params[:page], @count)
|
||||
@retries = @retries.map {|msg, score| [Sidekiq.load_json(msg), score] }
|
||||
slim :retries
|
||||
end
|
||||
|
||||
get '/scheduled' do
|
||||
@scheduled = scheduled
|
||||
@count = (params[:count] || 25).to_i
|
||||
(@current_page, @total_size, @scheduled) = page("schedule", params[:page], @count)
|
||||
@scheduled = @scheduled.map {|msg, score| [Sidekiq.load_json(msg), score] }
|
||||
slim :scheduled
|
||||
end
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ platforms :jruby do
|
|||
gem 'activerecord-jdbcsqlite3-adapter'
|
||||
end
|
||||
|
||||
gem 'rails', '3.2.2'
|
||||
gem 'rails', '3.2.6'
|
||||
gem 'sidekiq', :path => '..'
|
||||
gem 'capistrano'
|
||||
|
||||
|
|
15
web/views/_paging.slim
Normal file
15
web/views/_paging.slim
Normal file
|
@ -0,0 +1,15 @@
|
|||
- if @total_size > @count
|
||||
.pagination.pagination-right
|
||||
ul
|
||||
li class="#{'disabled' if @current_page == 1}"
|
||||
a href="#{url}?page=1" «
|
||||
- if @current_page > 1
|
||||
li
|
||||
a href="#{url}?page=#{@current_page - 1}" #{@current_page - 1}
|
||||
li.disabled
|
||||
a href="#{url}?page=#{@current_page}" #{@current_page}
|
||||
- if @total_size > @current_page * @count
|
||||
li class="#{'disabled' if @total_size <= @current_page * @count}"
|
||||
a href="#{url}?page=#{@current_page + 1}" #{@current_page + 1}
|
||||
li class="#{'disabled' if @total_size <= @current_page * @count}"
|
||||
a href="#{url}?page=#{(@total_size / @count).ceil + 1}" »
|
|
@ -1,5 +1,7 @@
|
|||
header
|
||||
h1 Latest messages in #{@name}
|
||||
h1 Current messages in #{@name}
|
||||
|
||||
== slim :_paging, :locals => { :url => "#{root_path}queues/#{@name}" }
|
||||
|
||||
table class="table table-striped table-bordered"
|
||||
tr
|
||||
|
@ -9,3 +11,5 @@ table class="table table-striped table-bordered"
|
|||
tr
|
||||
td= msg['class']
|
||||
td= msg['args'].inspect[0..100]
|
||||
|
||||
== slim :_paging, :locals => { :url => "#{root_path}queues/#{@name}" }
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
h1 Retries
|
||||
|
||||
- if @retries.size > 0
|
||||
== slim :_paging, :locals => { :url => "#{root_path}retries" }
|
||||
|
||||
form action="#{root_path}retries" method="post"
|
||||
table class="table table-striped table-bordered"
|
||||
tr
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
h1 Scheduled Jobs
|
||||
|
||||
- if @scheduled.size > 0
|
||||
== slim :_paging, :locals => { :url => "#{root_path}scheduled" }
|
||||
|
||||
form action="#{root_path}scheduled" method="post"
|
||||
table class="table table-striped table-bordered"
|
||||
tr
|
||||
|
|
Loading…
Add table
Reference in a new issue