Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for filtering jobs by "status" #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/resque/plugins/status/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ def self.count
# @param [Numeric] range_end The optional ending range
# @example retuning the last 20 statuses
# Resque::Plugins::Status::Hash.statuses(0, 20)
def self.statuses(range_start = nil, range_end = nil)
def self.statuses(range_start = nil, range_end = nil, filter=STATUSES)
filter = [filter || STATUSES].flatten
status_ids(range_start, range_end).collect do |id|
get(id)
h = get(id)
filter.include?(h.status) ? h : nil
end.compact
end

Expand Down
15 changes: 13 additions & 2 deletions lib/resque/server/views/statuses.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
<%= status_view :status_styles, :layout => false %>

<h1 class='wi'>Statuses</h1>
<form method="GET" action="<%= u(:statuses) %>" class='filter'>
<select name="filter">
<option value="">All Statuses</option>
<option value="completed" <%= 'selected' if @filter == 'completed' %>>Completed</option>
<option value="failed" <%= 'selected' if @filter == 'failed' %>>Failed</option>
<option value="working" <%= 'selected' if @filter == 'working' %>>Working</option>
<option value="queued" <%= 'selected' if @filter == 'queued' %>>Queued</option>
<option value="killed" <%= 'selected' if @filter == 'killed' %>>Killed</option>
</select>
<input type='submit' name='' value='Refresh' />
</form>
<%unless @statuses.empty?%>
<form method="POST" action="<%= u(:statuses) %>/clear" class='clear-failed'>
<input type='submit' name='' value='Clear Statuses' onclick='return confirm("Are you absolutely sure? This cannot be undone.");' />
Expand Down Expand Up @@ -46,10 +57,10 @@
</table>

<% unless @statuses.empty? %>
<%= partial :next_more, :start => @start, :size => @size %>
<%= partial :next_more, :start => @start, :size => @size, :per_page => @end - @start %>
<% end %>

<%= status_poll(@start) %>
<%= status_poll(@start, @filter) %>

<script type="text/javascript" charset="utf-8">
jQuery(function($) {
Expand Down
12 changes: 8 additions & 4 deletions lib/resque/status_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def self.registered(app)
app.get '/statuses' do
@start = params[:start].to_i
@end = @start + (params[:per_page] || 50)
@statuses = Resque::Plugins::Status::Hash.statuses(@start, @end)
@filter = params[:filter].blank? ? nil : params[:filter]
@statuses = Resque::Plugins::Status::Hash.statuses(@start, @end, @filter)
@size = @statuses.size
status_view(:statuses)
end
Expand Down Expand Up @@ -53,7 +54,8 @@ def self.registered(app)

@start = params[:start].to_i
@end = @start + (params[:per_page] || 50)
@statuses = Resque::Plugins::Status::Hash.statuses(@start, @end)
@filter = params[:filter].blank? ? nil : params[:filter]
@statuses = Resque::Plugins::Status::Hash.statuses(@start, @end, @filter)
@size = @statuses.size

status_view(:statuses, {:layout => false})
Expand All @@ -64,11 +66,13 @@ def status_view(filename, options = {}, locals = {})
erb(File.read(File.join(::Resque::StatusServer::VIEW_PATH, "#{filename}.erb")), options, locals)
end

def status_poll(start)
def status_poll(start, filter)
if @polling
text = "Last Updated: #{Time.now.strftime("%H:%M:%S")}"
else
text = "<a href='#{u(request.path_info)}.poll?start=#{start}' rel='poll'>Live Poll</a>"
querystring = "start=#{start}"
querystring += "&filter=#{filter}" if filter
text = "<a href='#{u(request.path_info)}.poll?#{querystring}' rel='poll'>Live Poll</a>"
end
"<p class='poll'>#{text}</p>"
end
Expand Down