Class: LiveQA::Processor::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/liveqa/processor/worker.rb

Constant Summary collapse

FLUSH_INTERVAL_SECONDS =
3
FLUSH_MESSAGE =
Object.new
SHUTDOWN_MESSAGE =
Object.new

Instance Method Summary collapse

Constructor Details

#initialize(queue, state) ⇒ Worker

Returns a new instance of Worker.



10
11
12
13
14
15
16
17
18
19
# File 'lib/liveqa/processor/worker.rb', line 10

def initialize(queue, state)
  @queue = queue
  @state = state

  @batch = Batch.new
  @promises = Concurrent::Array.new

  @timer = Concurrent::TimerTask.new(execution_interval: FLUSH_INTERVAL_SECONDS) { @queue << FLUSH_MESSAGE }
  @timer.execute
end

Instance Method Details

#runObject



21
22
23
24
25
26
27
28
29
# File 'lib/liveqa/processor/worker.rb', line 21

def run
  while thread_active?
    message = @queue.pop

    add_message_to_batch(message)
  end

  shutdown_worker
end