Skip to content
Browse files

Adding Resque::Scheduler.poll_sleep_amount

  • Loading branch information...
1 parent a537efa commit 4a9ba1774deeb68425839087bc2bd7628b72a025 @bvandenbos bvandenbos committed Jun 30, 2011
Showing with 21 additions and 1 deletion.
  1. +2 −0 HISTORY.md
  2. +9 −1 lib/resque/scheduler.rb
  3. +10 −0 test/scheduler_args_test.rb
View
2 HISTORY.md
@@ -5,6 +5,8 @@
## 2.0.0.e (2011-??-??)
* Adding enqueue_at_with_queue/enqueue_in_with_queue support (niralisse)
+* Adding `Resque::Scheduler.poll_sleep_amount` to allow for configuring
+ the sleep time b/w delayed queue polls.
## 2.0.0.d (2011-04-04)
View
10 lib/resque/scheduler.rb
@@ -17,11 +17,19 @@ class << self
# If set, will try to update the schulde in the loop
attr_accessor :dynamic
+
+ # Amount of time in seconds to sleep between polls of the delayed
+ # queue. Defaults to 5
+ attr_writer :poll_sleep_amount
# the Rufus::Scheduler jobs that are scheduled
def scheduled_jobs
@@scheduled_jobs
end
+
+ def poll_sleep_amount
+ @poll_sleep_amount ||= 5 # seconds
+ end
# Schedule all jobs and continually look for delayed jobs (never returns)
def run
@@ -245,7 +253,7 @@ def unschedule_job(name)
# Sleeps and returns true
def poll_sleep
@sleeping = true
- handle_shutdown { sleep 5 }
+ handle_shutdown { sleep poll_sleep_amount }
@sleeping = false
true
end
View
10 test/scheduler_args_test.rb
@@ -80,4 +80,14 @@
SomeIvarJob.expects(:perform).once.with('first_key' => {'second_key' => 'value'})
Resque.reserve('ivar').perform
end
+
+ test "poll_sleep_amount defaults to 5" do
+ assert_equal 5, Resque::Scheduler.poll_sleep_amount
+ end
+
+ test "poll_sleep_amount is settable" do
+ Resque::Scheduler.poll_sleep_amount = 1
+ assert_equal 1, Resque::Scheduler.poll_sleep_amount
+ end
+
end

0 comments on commit 4a9ba17

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