Skip to content

Commit

Permalink
Add a button in the web-ui to clear on completed statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
humancopy committed Aug 12, 2011
1 parent 29062cf commit 7609888
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/resque/server/views/statuses.erb
Expand Up @@ -2,9 +2,12 @@

<h1 class='wi'>Statuses</h1>
<%unless @statuses.empty?%>
<form method="POST" action="<%= u(:statuses) %>/clear" class='clear-failed'>
<form method="POST" action="<%= u(:statuses) %>/clear" class='clear-failed'>
<input type='submit' name='' value='Clear Statuses' />
</form>
<form method="POST" action="<%= u(:statuses) %>/clear/completed" class='clear-failed'>
<input type='submit' name='' value='Clear Completed Statuses' />
</form>
<%end%>
<p class='intro'>These are recent jobs created with the JobWithStatus class</p>
<table>
Expand Down
13 changes: 13 additions & 0 deletions lib/resque/status.rb
Expand Up @@ -47,6 +47,14 @@ def self.clear(range_start = nil, range_end = nil)
end
end

# clear only completed statuses from redis passing an optional range. See `statuses` for info
# about ranges
def self.clear_completed(range_start = nil, range_end = nil)
status_ids_with_status('completed', range_start, range_end).each do |id|
redis.del(status_key(id))
end
end

# returns a Redisk::Logger scoped to the UUID. Any options passed are passed
# to the logger initialization.
#
Expand Down Expand Up @@ -86,6 +94,11 @@ def self.status_ids(range_start = nil, range_end = nil)
end
end

# Return the <tt>num</tt> most recent status/job UUIDs which have a given status in reverse chronological order.
def self.status_ids_with_status(status_name, range_start = nil, range_end = nil)
statuses(range_start = nil, range_end = nil).select { |status| status.status == status_name }.collect { |status| status.uuid }
end

# Kill the job at UUID on its next iteration this works by adding the UUID to a
# kill list (a.k.a. a list of jobs to be killed. Each iteration the job checks
# if it _should_ be killed by calling <tt>tick</tt> or <tt>at</tt>. If so, it raises
Expand Down
5 changes: 5 additions & 0 deletions lib/resque/status_server.rb
Expand Up @@ -35,6 +35,11 @@ def self.registered(app)
Resque::Status.clear
redirect u(:statuses)
end

app.post '/statuses/clear/completed' do
Resque::Status.clear_completed
redirect u(:statuses)
end

app.get "/statuses.poll" do
content_type "text/plain"
Expand Down

0 comments on commit 7609888

Please sign in to comment.