Skip to content

Commit

Permalink
Add the default value for "interval" back to the "work" method. Also,…
Browse files Browse the repository at this point in the history
… always generate a random sleep-time between "interval" and 300 seconds
  • Loading branch information
jzaleski committed May 22, 2013
1 parent 90e6445 commit c9f7764
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/resque/worker.rb
Expand Up @@ -107,14 +107,18 @@ def validate_queues
#
# Also accepts a block which will be passed the job as soon as it
# has completed processing. Useful for testing.
def work(interval = nil, &block)
def work(interval = 5, &block)
$0 = "resque: Starting"
startup

# If an interval is not specified generate a random sleep time. Staggering
# the polling frequency should lessen the number of requests/sec that need
# to be serviced by redis.
interval = interval.nil? ? rand(5..300) : interval.to_i
# Ensure that interval is an integer value that is 0 or higher
interval = [0, interval.to_i].max

# Increasing and randomizing the polling frequency should help to lessen
# the average number of requests/sec that need to be serviced by redis.
# This value will only be used when there are no jobs in the queue that
# this worker can work on
interval = rand(interval..300)

loop do
break if shutdown?
Expand Down

0 comments on commit c9f7764

Please sign in to comment.