class Airbrake::AsyncSender

Responsible for sending notices to Airbrake asynchronously.

@see SyncSender @api private @since v1.0.0

Public Class Methods

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

Public Instance Methods

close() click to toggle source

@return [void]

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

@return [Boolean]

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

@return [Boolean]

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

Asynchronously sends a notice to Airbrake.

@param [Hash] payload Whatever needs to be sent @return [Airbrake::Promise]

# File lib/airbrake-ruby/async_sender.rb, line 20
def send(payload, promise, endpoint = @config.error_endpoint)
  unless thread_pool << [payload, promise, endpoint]
    return promise.reject(
      "AsyncSender has reached its capacity of #{@config.queue_size}",
    )
  end

  promise
end

Private Instance Methods

thread_pool() click to toggle source
# File lib/airbrake-ruby/async_sender.rb, line 47
def thread_pool
  @thread_pool ||= begin
    sender = SyncSender.new(@method)
    ThreadPool.new(
      name: @name,
      worker_size: @config.workers,
      queue_size: @config.queue_size,
      block: proc { |args| sender.send(*args) },
    )
  end
end