lib/upperkut/processor.rb in upperkut-0.6.0 vs lib/upperkut/processor.rb in upperkut-0.7.0
- old
+ new
@@ -1,13 +1,14 @@
require_relative 'batch_execution'
module Upperkut
class Processor
def initialize(manager)
- @manager = manager
- @worker = @manager.worker
- @logger = @manager.logger
+ @manager = manager
+ @worker = @manager.worker
+ @logger = @manager.logger
+ @strategy = @worker.strategy
@sleeping_time = 0
end
def run
@@ -33,29 +34,20 @@
private
def process
loop do
- if should_process?
+ next if @manager.stopped
+
+ if @strategy.process?
@sleeping_time = 0
process_batch
next
end
@sleeping_time += sleep(@worker.setup.polling_interval)
@logger.debug(sleeping_time: @sleeping_time)
end
- end
-
- def should_process?
- buffer_size = @worker.size
-
- return false if @manager.stopped
- return false if buffer_size.zero?
-
- # TODO: rename #setup by config
- buffer_size >= @worker.setup.batch_size ||
- @sleeping_time >= @worker.setup.max_wait
end
def process_batch
BatchExecution.new(@worker, @logger).execute
end