Module: QueueDaemon

Defined in:
lib/yodel/task_queue/queue_daemon.rb

Constant Summary collapse

IMMEDIATE_WORKERS =
1
DELAYED_WORKERS =
1

Class Method Summary collapse

Class Method Details

.runObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/yodel/task_queue/queue_daemon.rb', line 5

def self.run
  immediate_queue = TaskQueue.new(true)
  delayed_queue = TaskQueue.new(false)

  immediate_workers = []
  delayed_workers = []
  
  puts "Starting Workers..."
  stats_thread = StatsThread.new
  IMMEDIATE_WORKERS.times do
    immediate_workers << QueueWorker.new(immediate_queue, stats_thread)
  end

  DELAYED_WORKERS.times do
    delayed_workers << QueueWorker.new(delayed_queue, stats_thread)
  end
  
  Signal.trap('INT') do
    puts("Shutting down...")
    stats_thread.stop
    immediate_workers.each(&:stop)
    delayed_workers.each(&:stop)
  end

  immediate_workers.each {|worker| worker.join}
  delayed_workers.each {|worker| worker.join}
  puts "Shutdown complete"
end