Skip to content

Commit 9377687

Browse files
artobdefunkt
authored andcommitted
Allowed the poll interval to be specified as a floating point number.
This enables using poll intervals shorter than a second; for example, specifying INTERVAL=0.25 is now possible.
1 parent dbd04d6 commit 9377687

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/resque/worker.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,14 @@ def validate_queues
102102
# 2. Work loop: Jobs are pulled from a queue and processed.
103103
# 3. Teardown: This worker is unregistered.
104104
#
105-
# Can be passed an integer representing the polling frequency.
105+
# Can be passed a float representing the polling frequency.
106106
# The default is 5 seconds, but for a semi-active site you may
107107
# want to use a smaller value.
108108
#
109109
# Also accepts a block which will be passed the job as soon as it
110110
# has completed processing. Useful for testing.
111-
def work(interval = 5, &block)
111+
def work(interval = 5.0, &block)
112+
interval = interval.to_f
112113
$0 = "resque: Starting"
113114
startup
114115

@@ -133,10 +134,10 @@ def work(interval = 5, &block)
133134
done_working
134135
@child = nil
135136
else
136-
break if interval.to_i == 0
137-
log! "Sleeping for #{interval.to_i}"
137+
break if interval.zero?
138+
log! "Sleeping for #{interval} seconds"
138139
procline @paused ? "Paused" : "Waiting for #{@queues.join(',')}"
139-
sleep interval.to_i
140+
sleep interval
140141
end
141142
end
142143

0 commit comments

Comments
 (0)