Sha256: 368714625df8ea071965cbde6a3817957cea75d1b7f7840b5c035a8c05d852fe

Contents?: true

Size: 836 Bytes

Versions: 13

Compression:

Stored size: 836 Bytes

Contents

module Houston

  # Rescues exceptions and reports them
  def self.async(do_async=true)
    return yield unless do_async
    Thread.new do
      ActiveRecord::Base.connection_pool.with_connection do
        begin
          yield
        rescue Exception # rescues StandardError by default; but we want to rescue and report all errors
          Houston.report_exception($!)
        ensure
          Rails.logger.flush # http://stackoverflow.com/a/3516003/731300
        end
      end
    end
  end

  # Allows exceptions to bubble up
  def self.async!(do_async=true)
    return yield unless do_async
    Thread.new do
      ActiveRecord::Base.connection_pool.with_connection do
        begin
          yield
        ensure
          Rails.logger.flush # http://stackoverflow.com/a/3516003/731300
        end
      end
    end
  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
houston-core-0.9.2 config/initializers/houston_async.rb
houston-core-0.9.1 config/initializers/houston_async.rb
houston-core-0.9.0 config/initializers/houston_async.rb
houston-core-0.9.0.rc1 config/initializers/houston_async.rb
houston-core-0.8.4 config/initializers/houston_async.rb
houston-core-0.8.3 config/initializers/houston_async.rb
houston-core-0.8.2 config/initializers/houston_async.rb
houston-core-0.8.1 config/initializers/houston_async.rb
houston-core-0.8.0 config/initializers/houston_async.rb
houston-core-0.8.0.pre2 config/initializers/houston_async.rb
houston-core-0.8.0.pre config/initializers/houston_async.rb
houston-core-0.7.0 config/initializers/houston_async.rb
houston-core-0.7.0.beta4 config/initializers/houston_async.rb