mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Auto-prune old jobs from worker list, fixes #1508
This commit is contained in:
parent
d28cbf9135
commit
20b7a4fe47
5 changed files with 24 additions and 4 deletions
|
@ -1,3 +1,8 @@
|
|||
2.17.7
|
||||
-----------
|
||||
|
||||
- Auto-prune jobs older than one hour from the Workers page [#1508]
|
||||
|
||||
2.17.6
|
||||
-----------
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ module Sidekiq
|
|||
end
|
||||
|
||||
get "/workers" do
|
||||
erb :index
|
||||
erb :workers
|
||||
end
|
||||
|
||||
get "/queues" do
|
||||
|
|
|
@ -47,13 +47,28 @@ module Sidekiq
|
|||
end
|
||||
end
|
||||
|
||||
MAX_JOB_DURATION = 60*60
|
||||
|
||||
def workers
|
||||
@workers ||= begin
|
||||
to_rem = []
|
||||
workers = Sidekiq.redis do |conn|
|
||||
conn.smembers('workers').map do |w|
|
||||
msg = conn.get("worker:#{w}")
|
||||
msg ? [w, Sidekiq.load_json(msg)] : (to_rem << w; nil)
|
||||
if !msg
|
||||
to_rem << w
|
||||
nil
|
||||
else
|
||||
m = Sidekiq.load_json(msg)
|
||||
run_at = Time.at(m['run_at'])
|
||||
# prune jobs older than one hour
|
||||
if run_at < (Time.now - MAX_JOB_DURATION)
|
||||
to_rem << w
|
||||
nil
|
||||
else
|
||||
[w, m, run_at]
|
||||
end
|
||||
end
|
||||
end.compact.sort { |x| x[1] ? -1 : 1 }
|
||||
end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<th><%= t('Arguments') %></th>
|
||||
<th><%= t('Started') %></th>
|
||||
</thead>
|
||||
<% workers.each_with_index do |(worker, msg), index| %>
|
||||
<% workers.each_with_index do |(worker, msg, run_at), index| %>
|
||||
<tr>
|
||||
<td><%= worker %></td>
|
||||
<td>
|
||||
|
@ -16,7 +16,7 @@
|
|||
<td>
|
||||
<div class="args"><%= display_args(msg['payload']['args']) %></div>
|
||||
</td>
|
||||
<td><%= relative_time(msg['run_at'].is_a?(Numeric) ? Time.at(msg['run_at']) : Time.parse(msg['run_at'])) %></td>
|
||||
<td><%= relative_time(run_at) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
|
Loading…
Add table
Reference in a new issue