Class: Adrian::GirlFridayDispatcher

Inherits:
Dispatcher show all
Defined in:
lib/adrian/girl_friday_dispatcher.rb

Instance Attribute Summary

Attributes inherited from Dispatcher

#running

Instance Method Summary collapse

Methods inherited from Dispatcher

#initialize, #on_done, #on_failure, #start, #trap_stop_signals, #work_done

Constructor Details

This class inherits a constructor from Adrian::Dispatcher

Instance Method Details

#delegate_work(item, worker_class) ⇒ Object



21
22
23
# File 'lib/adrian/girl_friday_dispatcher.rb', line 21

def delegate_work(item, worker_class)
  gf_queue.push([item, worker_class])
end

#gf_queueObject



13
14
15
16
17
18
19
# File 'lib/adrian/girl_friday_dispatcher.rb', line 13

def gf_queue
  @gf_queue ||= GirlFriday::WorkQueue.new(gf_queue_name, :size => gf_queue_size) do |item, worker_class|
    worker = worker_class.new(item)
    worker.report_to(self)
    worker.perform
  end
end

#gf_queue_nameObject



5
6
7
# File 'lib/adrian/girl_friday_dispatcher.rb', line 5

def gf_queue_name
  @options[:name] || 'adrian_queue'
end

#gf_queue_sizeObject



9
10
11
# File 'lib/adrian/girl_friday_dispatcher.rb', line 9

def gf_queue_size
  @options[:size]
end

#stopObject



35
36
37
38
# File 'lib/adrian/girl_friday_dispatcher.rb', line 35

def stop
  super
  wait_for_empty
end

#wait_for_emptyObject



25
26
27
28
29
30
31
32
33
# File 'lib/adrian/girl_friday_dispatcher.rb', line 25

def wait_for_empty
  gf_queue.wait_for_empty

  sleep(0.5)

  while gf_queue.status[gf_queue_name][:busy] != 0
    sleep(0.5)
  end
end