lib/theatre/invocation.rb in adhearsion-1.2.4 vs lib/theatre/invocation.rb in adhearsion-1.2.5
- old
+ new
@@ -20,13 +20,14 @@
# @param [Proc] callback The block which should be executed by an Actor scheduler.
# @param [Object] payload The message that will be sent to the callback for processing.
#
def initialize(namespace, callback, payload=:theatre_no_payload)
raise ArgumentError, "Callback must be a Proc" unless callback.kind_of? Proc
+ @namespace = namespace
+ @callback = callback
@payload = payload
@unique_id = new_guid.freeze
- @callback = callback
@current_state = :new
@state_lock = Mutex.new
# Used just to protect access to the @returned_value instance variable
@returned_value_lock = Monitor.new
@@ -61,9 +62,17 @@
else
@callback.call @payload
end
with_state_lock { @current_state = :success }
rescue => e
+ if Array(@namespace).first =~ /exception/
+ # Exception encountered in exception handler. Do not perpetuate the loop.
+ ahn_log.error "Exception encountered in exception handler!"
+ ahn_log.error e.message
+ ahn_log.error e.backtrace.join("\n")
+ else
+ Adhearsion::Events.trigger('/exception', e)
+ end
@error = e
with_state_lock { @current_state = :error }
ensure
@finished_time = Time.now.freeze
end