class Airbrake::AsyncSender

Responsible for sending notices to Airbrake asynchronously.

@see SyncSender @api private @since v1.0.0

Constants

WILL_NOT_DELIVER_MSG

@return [String]

Public Class Methods

new(method = :post) click to toggle source
# File lib/airbrake-ruby/async_sender.rb, line 16
def initialize(method = :post)
  @config = Airbrake::Config.instance
  @method = method
end

Public Instance Methods

close() click to toggle source

@return [void]

# File lib/airbrake-ruby/async_sender.rb, line 35
def close
  thread_pool.close
end
closed?() click to toggle source

@return [Boolean]

# File lib/airbrake-ruby/async_sender.rb, line 40
def closed?
  thread_pool.closed?
end
has_workers?() click to toggle source

@return [Boolean]

# File lib/airbrake-ruby/async_sender.rb, line 45
def has_workers?
  thread_pool.has_workers?
end
send(notice, promise, endpoint = @config.endpoint) click to toggle source

Asynchronously sends a notice to Airbrake.

@param [Airbrake::Notice] notice A notice that was generated by the

library

@return [Airbrake::Promise]

# File lib/airbrake-ruby/async_sender.rb, line 26
def send(notice, promise, endpoint = @config.endpoint)
  unless thread_pool << [notice, promise, endpoint]
    return will_not_deliver(notice, promise)
  end

  promise
end

Private Instance Methods

thread_pool() click to toggle source
# File lib/airbrake-ruby/async_sender.rb, line 51
def thread_pool
  @thread_pool ||= begin
    sender = SyncSender.new(@method)
    ThreadPool.new(
      worker_size: @config.workers,
      queue_size: @config.queue_size,
      block: proc { |args| sender.send(*args) },
    )
  end
end
will_not_deliver(notice, promise) click to toggle source
# File lib/airbrake-ruby/async_sender.rb, line 62
def will_not_deliver(notice, promise)
  error = notice[:errors].first

  logger.error(
    format(
      WILL_NOT_DELIVER_MSG,
      log_label: LOG_LABEL,
      capacity: @config.queue_size,
      type: error[:type],
      message: error[:message],
      backtrace: error[:backtrace].map do |line|
        "#{line[:file]}:#{line[:line]} in `#{line[:function]}'"
      end.join("\n"),
    ),
  )
  promise.reject("AsyncSender has reached its capacity of #{@config.queue_size}")
end