Skip to content

Commit

Permalink
Adding size
Browse files Browse the repository at this point in the history
  • Loading branch information
bvandenbos authored and justinweiss committed Jul 22, 2010
1 parent 09c37ae commit 3ef8a88
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.gem
*.gem
nbproject
6 changes: 6 additions & 0 deletions lib/resque_unit/resque.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def self.run!
end
end

# Returns the size of the given queue
def self.size(queue)
self.reset! unless @queue
@queue[queue].length
end

# :nodoc:
def self.enqueue(klass, *args)
queue(queue_for(klass)) << {:klass => klass, :args => args}
Expand Down
8 changes: 8 additions & 0 deletions test/resque_unit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def setup
end
end

should "should be size 1" do
assert_equal 1, Resque.size(:low)
end

context ", when Resque.run! is called," do
setup do
assert !LowPriorityJob.run?, "The job should not have been run yet"
Expand Down Expand Up @@ -63,6 +67,10 @@ def setup
assert_queued(LowPriorityJob)
end
end

should "be size 0 when empty" do
assert_equal 0, Resque.size(:low)
end
end

context "A task that schedules a resque job with arguments" do
Expand Down

0 comments on commit 3ef8a88

Please sign in to comment.