Skip to content
Browse files

made job removal a lot more sane, added count_all_scheduled_jobs

  • Loading branch information...
1 parent 3958162 commit b02e2addc4c3a70cef6ef2aa0bb86f8bb418b798 @joshsz joshsz committed with bvandenbos Jul 15, 2010
Showing with 11 additions and 6 deletions.
  1. +9 −4 lib/resque_scheduler.rb
  2. +2 −2 test/delayed_queue_test.rb
View
13 lib/resque_scheduler.rb
@@ -122,14 +122,19 @@ def remove_delayed(klass, *args)
destroyed = 0
search = encode(job_to_hash(klass, args))
Array(redis.keys("delayed:*")).each do |key|
- newly_destroyed = redis.lrem key, 1, search
-
- clean_up_timestamp(key, key.split(/:/)[1]) if newly_destroyed > 0
- destroyed += newly_destroyed
+ destroyed += redis.lrem key, 0, search
end
destroyed
end
+ def count_all_scheduled_jobs
+ total_jobs = 0
+ Array(redis.zrange(:delayed_queue_schedule, 0, -1)).each do |timestamp|
+ total_jobs += redis.llen("delayed:#{timestamp}").to_i
+ end
+ total_jobs
+ end
+
private
def job_to_hash(klass, args)
{:class => klass.to_s, :args => args, :queue => queue_from_class(klass)}
View
4 test/delayed_queue_test.rb
@@ -182,7 +182,7 @@ def test_remove_specific_item_in_group_of_other_items_at_same_timestamp
Resque.enqueue_at(t, SomeIvarJob, "bar")
Resque.enqueue_at(t, SomeIvarJob, "baz")
- assert_equal(1, Resque.remove_delayed(SomeIvarJob, "bar"))
+ assert_equal(2, Resque.remove_delayed(SomeIvarJob, "bar"))
assert_equal(1, Resque.delayed_queue_schedule_size)
end
@@ -194,6 +194,6 @@ def test_remove_specific_item_in_group_of_other_items_at_different_timestamps
Resque.enqueue_at(t + 3, SomeIvarJob, "baz")
assert_equal(2, Resque.remove_delayed(SomeIvarJob, "bar"))
- assert_equal(2, Resque.delayed_queue_schedule_size)
+ assert_equal(2, Resque.count_all_scheduled_jobs)
end
end

0 comments on commit b02e2ad

Please sign in to comment.
Something went wrong with that request. Please try again.