Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Commit

Permalink
added drop down filter for exceptions on cleaner_list in the resque-w…
Browse files Browse the repository at this point in the history
…eb interface
  • Loading branch information
hamin committed Apr 7, 2011
1 parent a2e26b7 commit 31ba9af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/resque_cleaner/server.rb
Expand Up @@ -10,7 +10,7 @@ def self.public_path(filename)
File.join(File.dirname(__FILE__), 'server', 'public', filename)
end

# Pagination helpr for list page.
# Pagination helper for list page.
class Paginate
attr_accessor :page_size, :page, :jobs, :url
def initialize(jobs, url, page=1, page_size=20)
Expand Down Expand Up @@ -87,6 +87,16 @@ def class_filter(id, name, klasses, value)
end
html += "</select>"
end

def exception_filter(id, name, exceptions, value)
html = "<select id=\"#{id}\" name=\"#{name}\">"
html += "<option value=\"\">-</option>"
exceptions.each do |ex|
selected = ex == value ? 'selected="selected"' : ''
html += "<option #{selected} value=\"#{ex}\">#{ex}</option>"
end
html += "</select>"
end
end

get "/cleaner" do
Expand Down Expand Up @@ -121,10 +131,11 @@ def class_filter(id, name, klasses, value)

@failed = cleaner.select(&block).reverse

url = "cleaner_list?c=#{@klass}&f=#{@from}&t=#{@to}"
url = "cleaner_list?c=#{@klass}&ex=#{@exception}f=#{@from}&t=#{@to}"
@paginate = Paginate.new(@failed, url, params[:p].to_i)

@klasses = cleaner.stats_by_class.keys
@exceptions = cleaner.stats_by_exception.keys
@count = cleaner.select(&block).size

erb File.read(ResqueCleaner::Server.erb_path('cleaner_list.erb'))
Expand All @@ -148,7 +159,7 @@ def class_filter(id, name, klasses, value)
when "retry" then cleaner.requeue(false,{},&block)
end

@url = "cleaner_list?c=#{@klass}&f=#{@from}&t=#{@to}"
@url = "cleaner_list?c=#{@klass}&ex=#{@exception}&f=#{@from}&t=#{@to}"
erb File.read(ResqueCleaner::Server.erb_path('cleaner_exec.erb'))
end

Expand Down Expand Up @@ -184,13 +195,15 @@ def load_cleaner_filter
@from = params[:f]=="" ? nil : params[:f]
@to = params[:t]=="" ? nil : params[:t]
@klass = params[:c]=="" ? nil : params[:c]
@exception = params[:ex]=="" ? nil : params[:ex]
end

def filter_block
block = lambda{|j|
(!@from || j.after?(hours_ago(@from))) &&
(!@to || j.before?(hours_ago(@to))) &&
(!@klass || j.klass?(@klass)) &&
(!@klass || j.klass?(@klass)) &&
(!@exception || j.exception?(@exception)) &&
(!@sha1 || @sha1[Digest::SHA1.hexdigest(j.to_json)])
}
end
Expand Down
3 changes: 3 additions & 0 deletions lib/resque_cleaner/server/views/cleaner_list.erb
Expand Up @@ -11,6 +11,9 @@
<form method="get">
<span class="class_filter">
Class: <%= class_filter("filter_class","c",@klasses,@klass)%>
</span>
<span class="class_filter">
Exception: <%= exception_filter("filter_class","ex",@exceptions,@exception)%>
</span>
<span class="time_filter">
From: <%= time_filter("filter_from","f",@from)%>
Expand Down

0 comments on commit 31ba9af

Please sign in to comment.