Class: Karafka::Web::Tracking::Helpers::Ttls::Hash

Inherits:
Hash
  • Object
show all
Defined in:
lib/karafka/web/tracking/helpers/ttls/hash.rb

Overview

Hash that accumulates data that has an expiration date (ttl) Used to keep track of metrics in a window

Instance Method Summary collapse

Constructor Details

#initialize(ttl) ⇒ Hash

Returns a new instance of Hash.

Parameters:

  • ttl (Integer)

    milliseconds ttl



12
13
14
# File 'lib/karafka/web/tracking/helpers/ttls/hash.rb', line 12

def initialize(ttl)
  super() { |k, v| k[v] = Ttls::Array.new(ttl) }
end

Instance Method Details

#stats_from(&block) {|key, samples| ... } ⇒ Stats

Takes a block where we provide a hash select filtering to select keys we are interested in using for aggregated stats. Once filtered, builds a Stats object out of the candidates

Parameters:

  • block (Proc)

    block for selection of elements for stats

Yield Parameters:

Returns:



24
25
26
27
28
# File 'lib/karafka/web/tracking/helpers/ttls/hash.rb', line 24

def stats_from(&block)
  Stats.new(
    select(&block)
  )
end