Class: Airbrake::Backlog Private

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/airbrake-ruby/backlog.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Backlog accepts notices and APM events and synchronously sends them in the background at regular intervals. The backlog is a queue of data that failed to be sent due to some error. In a nutshell, it’s a retry mechanism.

Since:

  • v6.2.0

Constant Summary collapse

BACKLOG_SIZE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Returns how many records to keep in the backlog.

Returns:

  • (Integer)

    how many records to keep in the backlog

Since:

  • v6.2.0

100
TWO_MINUTES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Returns flush period in seconds.

Returns:

  • (Integer)

    flush period in seconds

Since:

  • v6.2.0

60 * 2

Instance Method Summary collapse

Methods included from Loggable

#logger

Constructor Details

#initialize(sync_sender, flush_period = TWO_MINUTES) ⇒ Backlog

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Backlog.

Since:

  • v6.2.0



17
18
19
20
21
22
23
24
25
# File 'lib/airbrake-ruby/backlog.rb', line 17

def initialize(sync_sender, flush_period = TWO_MINUTES)
  @sync_sender = sync_sender
  @flush_period = flush_period
  @queue = SizedQueue.new(BACKLOG_SIZE).extend(MonitorMixin)
  @has_backlog_data = @queue.new_cond
  @schedule_flush = nil

  @seen = Set.new
end

Instance Method Details

#<<(data) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Appends data to the backlog. Once appended, the flush schedule will start. Chainable.

Examples:

backlog << [{ 'data' => 1 }, 'https://airbrake.io/api']

Parameters:

  • data (Array<#to_json, String>)

    An array of two elements, where the first element is the data we are sending and the second element is the URL that we are sending to

Returns:

  • (self)

Since:

  • v6.2.0



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/airbrake-ruby/backlog.rb', line 37

def <<(data)
  @queue.synchronize do
    return self if @seen.include?(data)

    @seen << data

    begin
      @queue.push(data, true)
    rescue ThreadError
      logger.error("#{LOG_LABEL} Airbrake::Backlog full")
      return self
    end

    @has_backlog_data.signal
    schedule_flush

    self
  end
end

#closevoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Closes all the resources that this sender has allocated.

Since:

  • v6.2.0



61
62
63
64
65
66
67
68
# File 'lib/airbrake-ruby/backlog.rb', line 61

def close
  @queue.synchronize do
    if @schedule_flush
      @schedule_flush.kill
      logger.debug("#{LOG_LABEL} Airbrake::Backlog closed")
    end
  end
end