Class: Adrian::GirlFridayDispatcher
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
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_queue ⇒ Object
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_name ⇒ Object
5
6
7
|
# File 'lib/adrian/girl_friday_dispatcher.rb', line 5
def gf_queue_name
@options[:name] || 'adrian_queue'
end
|
#gf_queue_size ⇒ Object
9
10
11
|
# File 'lib/adrian/girl_friday_dispatcher.rb', line 9
def gf_queue_size
@options[:size]
end
|
#stop ⇒ Object
35
36
37
38
|
# File 'lib/adrian/girl_friday_dispatcher.rb', line 35
def stop
super
wait_for_empty
end
|
#wait_for_empty ⇒ Object
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
|