Method: Honeybadger::Agent#flush

Defined in:
lib/honeybadger/agent.rb

#flush { ... } ⇒ Object, Boolean

Flushes all data from workers before returning. This is most useful in tests when using the test backend, where normally the asynchronous nature of this library could create race conditions.

Examples:

# Without a block:
it "sends a notification to Honeybadger" do
  expect {
    Honeybadger.notify(StandardError.new('test backend'))
    Honeybadger.flush
  }.to change(Honeybadger::Backend::Test.notifications[:notices], :size).by(0)
end

# With a block:
it "sends a notification to Honeybadger" do
  expect {
    Honeybadger.flush do
      49.times do
        Honeybadger.notify(StandardError.new('test backend'))
      end
    end
  }.to change(Honeybadger::Backend::Test.notifications[:notices], :size).by(49)
end

Yields:

  • An optional block to execute (exceptions will propagate after data is flushed).

Returns:

  • (Object, Boolean)

    value of block if block is given, otherwise true on success or false if Honeybadger isn’t running.

[View source]

365
366
367
368
369
370
371
372
# File 'lib/honeybadger/agent.rb', line 365

def flush
  return true unless block_given?
  yield
ensure
  worker.flush
  events_worker&.flush
  metrics_worker&.flush
end