mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Add ability to sort 'Enqueued' page on Web UI by enqueued_at time
This commit is contained in:
parent
b5eb468c7c
commit
8243c55f25
9 changed files with 42 additions and 8 deletions
|
@ -5,6 +5,7 @@
|
|||
HEAD
|
||||
---------
|
||||
|
||||
- Add ability to sort 'Enqueued' page on Web UI by enqueued_at time [#4248]
|
||||
- Support `Client.push_bulk` with different delays [#4243]
|
||||
```ruby
|
||||
Sidekiq::Client.push_bulk("class" => FooJob, "args" => [[1], [2]], "at" => [1.minute.from_now.to_f, 5.minutes.from_now.to_f])
|
||||
|
|
|
@ -12,10 +12,10 @@ module Sidekiq
|
|||
|
||||
Sidekiq.redis do |conn|
|
||||
type = conn.type(key)
|
||||
rev = opts && opts[:reverse]
|
||||
|
||||
case type
|
||||
when "zset"
|
||||
rev = opts && opts[:reverse]
|
||||
total_size, items = conn.multi {
|
||||
conn.zcard(key)
|
||||
if rev
|
||||
|
@ -28,8 +28,13 @@ module Sidekiq
|
|||
when "list"
|
||||
total_size, items = conn.multi {
|
||||
conn.llen(key)
|
||||
conn.lrange(key, starting, ending)
|
||||
if rev
|
||||
conn.lrange(key, -ending - 1, -starting - 1)
|
||||
else
|
||||
conn.lrange(key, starting, ending)
|
||||
end
|
||||
}
|
||||
items.reverse! if rev
|
||||
[current_page, total_size, items]
|
||||
when "none"
|
||||
[1, 0, []]
|
||||
|
|
|
@ -84,7 +84,7 @@ module Sidekiq
|
|||
|
||||
@count = (params["count"] || 25).to_i
|
||||
@queue = Sidekiq::Queue.new(@name)
|
||||
(@current_page, @total_size, @messages) = page("queue:#{@name}", params["page"], @count)
|
||||
(@current_page, @total_size, @messages) = page("queue:#{@name}", params["page"], @count, reverse: params["direction"] == "asc")
|
||||
@messages = @messages.map { |msg| Sidekiq::Job.new(msg, @name) }
|
||||
|
||||
erb(:queue)
|
||||
|
|
|
@ -130,6 +130,10 @@ module Sidekiq
|
|||
end
|
||||
end
|
||||
|
||||
def sort_direction_label
|
||||
params[:direction] == "asc" ? "↑" : "↓"
|
||||
end
|
||||
|
||||
def workers
|
||||
@workers ||= Sidekiq::Workers.new
|
||||
end
|
||||
|
@ -189,7 +193,7 @@ module Sidekiq
|
|||
[score.to_f, jid]
|
||||
end
|
||||
|
||||
SAFE_QPARAMS = %w[page poll]
|
||||
SAFE_QPARAMS = %w[page poll direction]
|
||||
|
||||
# Merge options with current params, filter safe params, and stringify to query string
|
||||
def qparams(options)
|
||||
|
|
|
@ -134,9 +134,25 @@ describe Sidekiq::Web do
|
|||
assert_equal 200, last_response.status
|
||||
end
|
||||
|
||||
it 'can sort on enqueued_at column' do
|
||||
Sidekiq.redis do |conn|
|
||||
(1000..1005).each do |i|
|
||||
conn.lpush('queue:default', Sidekiq.dump_json(args: [i], enqueued_at: Time.now.to_i + i))
|
||||
end
|
||||
end
|
||||
|
||||
get '/queues/default?count=3' # direction is 'desc' by default
|
||||
assert_match(/1005/, last_response.body)
|
||||
refute_match(/1002/, last_response.body)
|
||||
|
||||
get '/queues/default?count=3&direction=asc'
|
||||
assert_match(/1000/, last_response.body)
|
||||
refute_match(/1003/, last_response.body)
|
||||
end
|
||||
|
||||
it 'can delete a queue' do
|
||||
Sidekiq.redis do |conn|
|
||||
conn.rpush('queue:foo', '{\"args\":[]}')
|
||||
conn.rpush('queue:foo', "{\"args\":[],\"enqueued_at\":1567894960}")
|
||||
conn.sadd('queues', 'foo')
|
||||
end
|
||||
|
||||
|
@ -154,9 +170,9 @@ describe Sidekiq::Web do
|
|||
|
||||
it 'can delete a job' do
|
||||
Sidekiq.redis do |conn|
|
||||
conn.rpush('queue:foo', "{\"args\":[]}")
|
||||
conn.rpush('queue:foo', "{\"foo\":\"bar\",\"args\":[]}")
|
||||
conn.rpush('queue:foo', "{\"foo2\":\"bar2\",\"args\":[]}")
|
||||
conn.rpush('queue:foo', '{"args":[],"enqueued_at":1567894960}')
|
||||
conn.rpush('queue:foo', '{"foo":"bar","args":[],"enqueued_at":1567894960}')
|
||||
conn.rpush('queue:foo', '{"foo2":"bar2","args":[],"enqueued_at":1567894960}')
|
||||
end
|
||||
|
||||
get '/queues/foo'
|
||||
|
|
|
@ -77,5 +77,6 @@ en: # <---- change this to your locale code
|
|||
Plugins: Plugins
|
||||
NotYetEnqueued: Not yet enqueued
|
||||
CreatedAt: Created At
|
||||
EnqueuedAt: Enqueued At
|
||||
BackToApp: Back to App
|
||||
Latency: Latency
|
||||
|
|
|
@ -75,4 +75,5 @@ ru:
|
|||
Plugins: Плагины
|
||||
NotYetEnqueued: Пока не в очереди
|
||||
CreatedAt: Создан
|
||||
EnqueuedAt: Поставлен в очередь
|
||||
BackToApp: Назад
|
||||
|
|
|
@ -74,3 +74,4 @@ uk:
|
|||
PollingInterval: Інтервал опитування
|
||||
Plugins: Плагіни
|
||||
NotYetEnqueued: Ще не в черзі
|
||||
EnqueuedAt: Відправлено до черги
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
<thead>
|
||||
<th><%= t('Job') %></th>
|
||||
<th><%= t('Arguments') %></th>
|
||||
<th>
|
||||
<a href="<%= url %>?direction=<%= params[:direction] == 'asc' ? 'desc' : 'asc' %>"><%= t('EnqueuedAt') %> <%= sort_direction_label %></th></a>
|
||||
<th></th>
|
||||
</thead>
|
||||
<% @messages.each_with_index do |msg, index| %>
|
||||
|
@ -32,6 +34,9 @@
|
|||
<%= display_args(msg.display_args) %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<%= relative_time(msg.enqueued_at) %>
|
||||
</td>
|
||||
<td>
|
||||
<form action="<%= root_path %>queues/<%= CGI.escape(@name) %>/delete" method="post">
|
||||
<%= csrf_tag %>
|
||||
|
|
Loading…
Add table
Reference in a new issue