Module: Eventboss::SafeThread

Included in:
LongPoller, UnitOfWork, Worker
Defined in:
lib/eventboss/safe_thread.rb

Overview

SafeThread includes thread handling with automatic error reporting

Instance Method Summary collapse

Instance Method Details

#handle_exception(exception, context) ⇒ Object



16
17
18
19
20
21
# File 'lib/eventboss/safe_thread.rb', line 16

def handle_exception(exception, context)
  context.freeze
  Eventboss.configuration.error_handlers.each do |handler|
    handler.call(exception, context)
  end
end

#safe_thread(name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/eventboss/safe_thread.rb', line 4

def safe_thread(name)
  Thread.new do
    begin
      Thread.current[:ah_eventboss_label] = name
      yield
    rescue Exception => exception
      handle_exception(exception, name: name)
      raise exception
    end
  end
end