Class: Honeybadger::Agent::Batch
- Inherits:
-
Object
- Object
- Honeybadger::Agent::Batch
- Defined in:
- lib/honeybadger/agent/batch.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #as_json(*args) ⇒ Object
- #empty? ⇒ Boolean
- #flush? ⇒ Boolean
-
#initialize(config, name, opts = {}) ⇒ Batch
constructor
A new instance of Batch.
- #push(val) ⇒ Object
- #size ⇒ Object
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
#id ⇒ Object (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
23 24 25 |
# File 'lib/honeybadger/agent/batch.rb', line 23 def empty? mutex.synchronize { values.empty? } end |
#flush? ⇒ 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 |
#size ⇒ Object
27 28 29 |
# File 'lib/honeybadger/agent/batch.rb', line 27 def size mutex.synchronize { values.size } end |