Method: Narou::Worker#start

Defined in:
lib/web/worker.rb

#startObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/web/worker.rb', line 28

def start
  return if running?
  @worker_thread = Thread.new do
    loop do
      begin
        q = @queue.pop
        if canceled?
          @queue.clear
          @cancel_signal = false
        else
          #q[:block].call
          @thread_of_block_executing = Thread.new do
            q[:block].call
          end
          @thread_of_block_executing.tap do |th|
            th.join
            th = nil
          end
        end
      rescue SystemExit
      rescue Exception => e
        # Workerスレッド内での例外は表示するだけしてスレッドは生かしたままにする
        STDOUT.puts $@.shift + ": #{e.message} (#{e.class})"
        $@.each do |b|
          STDOUT.puts "  from #{b}"
        end
      ensure
        if q[:counting]
          countdown
          notification_queue
        end
      end
    end
  end
end