Sha256: 4acdb1925ec87541610ddb65428cf7f186ea6f02f59eff329fb3cccca7c70a9f

Contents?: true

Size: 901 Bytes

Versions: 21

Compression:

Stored size: 901 Bytes

Contents

module CronoTrigger
  class ExceptionHandler
    def self.handle_exception(record, ex)
      new(record).handle_exception(ex)
    end

    def initialize(record)
      @record = record
    end

    def handle_exception(ex)
      handlers = CronoTrigger.config.error_handlers + Array(@record.crono_trigger_options[:error_handlers])
      handlers.each do |callable|
        callable, arity = ensure_callable(callable)
        args = [ex, @record]
        args = arity < 0 ? args : args.take(arity)
        callable.call(*args)
      end
    rescue Exception => e
      @record.logger.error("CronoTrigger error handler raises error")
      @record.logger.error(e)
    end

    private

    def ensure_callable(callable)
      if callable.respond_to?(:call)
        return callable, callable.arity
      elsif callable.is_a?(Symbol)
        return @record.method(callable), 1
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
crono_trigger-0.8.3 lib/crono_trigger/exception_handler.rb
crono_trigger-0.8.1 lib/crono_trigger/exception_handler.rb
crono_trigger-0.8.0 lib/crono_trigger/exception_handler.rb
crono_trigger-0.7.1 lib/crono_trigger/exception_handler.rb
crono_trigger-0.7.0 lib/crono_trigger/exception_handler.rb
crono_trigger-0.6.4 lib/crono_trigger/exception_handler.rb
crono_trigger-0.6.3 lib/crono_trigger/exception_handler.rb
crono_trigger-0.6.2 lib/crono_trigger/exception_handler.rb
crono_trigger-0.6.1 lib/crono_trigger/exception_handler.rb
crono_trigger-0.6.0 lib/crono_trigger/exception_handler.rb
crono_trigger-0.5.4 lib/crono_trigger/exception_handler.rb
crono_trigger-0.5.3 lib/crono_trigger/exception_handler.rb
crono_trigger-0.5.2 lib/crono_trigger/exception_handler.rb
crono_trigger-0.5.1 lib/crono_trigger/exception_handler.rb
crono_trigger-0.5.0 lib/crono_trigger/exception_handler.rb
crono_trigger-0.4.0 lib/crono_trigger/exception_handler.rb
crono_trigger-0.3.4 lib/crono_trigger/exception_handler.rb
crono_trigger-0.3.2 lib/crono_trigger/exception_handler.rb
crono_trigger-0.3.0 lib/crono_trigger/exception_handler.rb
crono_trigger-0.2.0 lib/crono_trigger/exception_handler.rb