Sha256: a0c1c91cd44f8ecbdb8f8ac9bfff16de9b8d0cea206fe3e5062c5b19f1c700f6
Contents?: true
Size: 1.04 KB
Versions: 39
Compression:
Stored size: 1.04 KB
Contents
require 'securerandom' module Honeybadger class Agent class Batch 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 attr_reader :id def push(val) mutex.synchronize { values.push(val) } end def empty? mutex.synchronize { values.empty? } end def size mutex.synchronize { values.size } end def flush? size >= max || now >= future end def as_json(*args) mutex.synchronize do { name => values.map(&:to_h), :environment => config[:env], :hostname => config[:hostname] } end end private attr_reader :config, :name, :max, :interval, :values, :future, :mutex def now Time.now.to_i end end end end
Version data entries
39 entries across 39 versions & 2 rubygems