Class: Honeybadger::Agent::Batch

Inherits:
Object
  • Object
show all
Defined in:
lib/honeybadger/agent/batch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, name, opts = {}) ⇒ Batch

Returns a new instance of Batch.



6
7
8
9
10
11
12
13
14
15
# File 'lib/honeybadger/agent/batch.rb', line 6

def initialize(config, name, opts = {})
  @id = SecureRandom.uuid
  @config = config
  @name = name
  @max = opts.fetch(:max, 100)
  @interval = opts.fetch(:interval, 60)
  @future = opts.fetch(:now, now()) + interval
  @values = opts.fetch(:collection, Array.new)
  @mutex = Mutex.new
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



17
18
19
# File 'lib/honeybadger/agent/batch.rb', line 17

def id
  @id
end

Instance Method Details

#as_json(*args) ⇒ Object



35
36
37
38
39
# File 'lib/honeybadger/agent/batch.rb', line 35

def as_json(*args)
  mutex.synchronize do
    { name => values.map(&:to_h), :environment => config[:env], :hostname => config[:hostname] }
  end
end

#empty?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/honeybadger/agent/batch.rb', line 23

def empty?
  mutex.synchronize { values.empty? }
end

#flush?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/honeybadger/agent/batch.rb', line 31

def flush?
  size >= max || now >= future
end

#push(val) ⇒ Object



19
20
21
# File 'lib/honeybadger/agent/batch.rb', line 19

def push(val)
  mutex.synchronize { values.push(val) }
end

#sizeObject



27
28
29
# File 'lib/honeybadger/agent/batch.rb', line 27

def size
  mutex.synchronize { values.size }
end