Class: LaunchDarkly::EventSummarizer

Inherits:
Object
  • Object
show all
Defined in:
lib/ldclient-rb/event_summarizer.rb

Overview

Manages the state of summarizable information for the EventProcessor, including the event counters and user deduplication. Note that the methods of this class are deliberately not thread-safe; the EventProcessor is responsible for enforcing synchronization across both the summarizer and the event queue.

Instance Method Summary collapse

Constructor Details

#initializeEventSummarizer

Returns a new instance of EventSummarizer.



13
14
15
# File 'lib/ldclient-rb/event_summarizer.rb', line 13

def initialize
  clear
end

Instance Method Details

#clearObject



49
50
51
52
53
# File 'lib/ldclient-rb/event_summarizer.rb', line 49

def clear
  @start_date = 0
  @end_date = 0
  @counters = {}
end

#snapshotObject

Returns a snapshot of the current summarized event data, and resets this state.



44
45
46
47
# File 'lib/ldclient-rb/event_summarizer.rb', line 44

def snapshot
  ret = EventSummary.new(@start_date, @end_date, @counters)
  ret
end

#summarize_event(event) ⇒ Object

Adds this event to our counters, if it is a type of event we need to count.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ldclient-rb/event_summarizer.rb', line 18

def summarize_event(event)
  if event[:kind] == "feature"
    counter_key = {
      key: event[:key],
      version: event[:version],
      variation: event[:variation]
    }
    c = @counters[counter_key]
    if c.nil?
      @counters[counter_key] = {
        value: event[:value],
        default: event[:default],
        count: 1
      }
    else
      c[:count] = c[:count] + 1
    end
    time = event[:creationDate]
    if !time.nil?
      @start_date = time if @start_date == 0 || time < @start_date
      @end_date = time if time > @end_date
    end
  end
end