Permalink
Browse files

Auto-prune old jobs from worker list, fixes #1508

  • Loading branch information...
mperham committed Feb 22, 2014
1 parent d28cbf9 commit 20b7a4fe47585ce9c43981305d146bd087540bbf
Showing with 24 additions and 4 deletions.
  1. +5 −0 Changes.md
  2. +1 −1 lib/sidekiq/web.rb
  3. +16 −1 lib/sidekiq/web_helpers.rb
  4. +2 −2 web/views/_workers.erb
  5. 0 web/views/{index.erb → workers.erb}
View
@@ -1,3 +1,8 @@
+2.17.7
+-----------
+
+- Auto-prune jobs older than one hour from the Workers page [#1508]
+
2.17.6
-----------
View
@@ -38,7 +38,7 @@ def custom_tabs
end
get "/workers" do
- erb :index
+ erb :workers
end
get "/queues" do
View
@@ -47,13 +47,28 @@ def workers_size
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
View
@@ -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>
File renamed without changes.

0 comments on commit 20b7a4f

Please sign in to comment.