Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: quirkey/resque-status
base: master
...
head fork: mattetti/resque-status
compare: master
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
7 lib/resque/job_with_status.rb
View
@@ -87,6 +87,13 @@ def self.perform(uuid, options = {})
instance.safe_perform!
instance
end
+
+ # Wrapper API to forward a Resque::Job creation API call into a JobWithStatus call.
+ # This is needed to be used with resque scheduler
+ # http://github.com/bvandenbos/resque-scheduler
+ def self.scheduled(queue, klass, *args)
+ create(args)
+ end
# Create a new instance with <tt>uuid</tt> and <tt>options</tt>
def initialize(uuid, options = {})
4 lib/resque/server/views/statuses.erb
View
@@ -39,6 +39,10 @@
<% end %>
</table>
+<% unless @statuses.empty? %>
+ <%= partial :next_more, :start => @start, :size => @size %>
+<% end %>
+
<%= poll %>
<script type="text/javascript" charset="utf-8">
32 lib/resque/status.rb
View
@@ -53,18 +53,42 @@ def self.logger(uuid, options = {})
Redisk.redis = redis
Redisk::Logger.new(logger_key(uuid), options)
end
+
+ def self.count
+ redis.zcard(set_key)
+ end
# Return <tt>num</tt> Resque::Status objects in reverse chronological order.
# By default returns the entire set.
- def self.statuses(num = -1)
- status_ids(num).collect do |id|
+ # @param [Numeric] range_start The optional starting range
+ # @param [Numeric] range_end The optional ending range
+ # @example retuning the last 20 statuses
+ # Resque::Status.statuses(0, 20)
+ def self.statuses(range_start=nil, range_end=nil)
+ status_ids(range_start, range_end).collect do |id|
get(id)
end.compact
end
# Return the <tt>num</tt> most recent status/job UUIDs in reverse chronological order.
- def self.status_ids(num = -1)
- redis.zrevrange(set_key, 0, num) || []
+ def self.status_ids(range_start=nil, range_end=nil)
+ unless range_end && range_start
+ # Because we want a reverse chronological order, we need to get a range starting
+ # by the higest negative number.
+ redis.zrevrange(set_key, 0, -1) || []
+ else
+ # Because we want a reverse chronological order, we need to get a range starting
+ # by the higest negative number. The ordering is transparent from the API user's
+ # perspective so we need to convert the passed params
+ if range_start == 0
+ range_start = -1
+ else
+ range_end -= 1
+ end
+
+
+ (redis.zrevrange(set_key, -(range_end.abs), -(range_start.abs)) || []).reverse
+ end
end
# Kill the job at UUID on its next iteration this works by adding the UUID to a
5 lib/resque/status_server.rb
View
@@ -8,7 +8,10 @@ module StatusServer
def self.registered(app)
app.get '/statuses' do
- @statuses = Resque::Status.statuses
+ @start = params[:start].to_i
+ @end = @start + (params[:per_page] || 50)
+ @statuses = Resque::Status.statuses(@start, @end)
+ @size = @statuses.size
status_view(:statuses)
end
23 test/test_resque-status.rb
View
@@ -87,8 +87,21 @@ class TestResqueStatus < Test::Unit::TestCase
end
context ".status_ids" do
+
+ setup do
+ @uuids = []
+ 30.times{ Resque::Status.create }
+ end
+
should "return an array of job ids" do
assert Resque::Status.status_ids.is_a?(Array)
+ assert_equal 32, Resque::Status.status_ids.size # 30 + 2
+ end
+
+ should "let you paginate through the statuses" do
+ assert_equal Resque::Status.status_ids.reverse[0, 10], Resque::Status.status_ids(0, 10)
+ assert_equal Resque::Status.status_ids.reverse[9, 10], Resque::Status.status_ids(10, 20)
+ # assert_equal Resque::Status.status_ids.reverse[0, 10], Resque::Status.status_ids(0, 10)
end
end
@@ -102,6 +115,16 @@ class TestResqueStatus < Test::Unit::TestCase
end
+ # context ".count" do
+ #
+ # should "return a count of statuses" do
+ # statuses = Resque::Status.statuses
+ # assert_equal 2, statuses.size
+ # assert_equal statuses.size, Resque::Status.count
+ # end
+ #
+ # end
+
context ".logger" do
setup do
@logger = Resque::Status.logger(@uuid)

No commit comments for this range

Something went wrong with that request. Please try again.