lib/cloud_crowd/daemon.rb in documentcloud-cloud-crowd-0.0.2 vs lib/cloud_crowd/daemon.rb in documentcloud-cloud-crowd-0.0.3
- old
+ new
@@ -8,16 +8,16 @@
# a loop, continually fetching and processing WorkUnits from the central
# server. The Daemon backs off and pings central less frequently when there
# isn't any work to be done, and speeds back up when there is.
class Daemon
- DEFAULT_WAIT = CloudCrowd.config[:default_worker_wait]
+ MIN_WAIT = CloudCrowd.config[:min_worker_wait]
MAX_WAIT = CloudCrowd.config[:max_worker_wait]
WAIT_MULTIPLIER = CloudCrowd.config[:worker_wait_multiplier]
def initialize
- @wait_time = DEFAULT_WAIT
+ @wait_time = MIN_WAIT
@worker = CloudCrowd::Worker.new
Signal.trap('INT', 'EXIT')
Signal.trap('KILL', 'EXIT')
Signal.trap('TERM', 'EXIT')
end
@@ -29,12 +29,14 @@
# In either case, nasty un-cleaned-up bits might be left behind.
def run
loop do
@worker.fetch_work_unit
if @worker.has_work?
- @worker.run
- @wait_time = DEFAULT_WAIT
- sleep 0.01 # So as to listen for incoming signals.
+ @wait_time = MIN_WAIT
+ while @worker.has_work?
+ @worker.run
+ sleep 0.01 # So as to listen for incoming signals.
+ end
else
@wait_time = [@wait_time * WAIT_MULTIPLIER, MAX_WAIT].min
sleep @wait_time
end
end
\ No newline at end of file