Class: AfElastic::EventStore

Inherits:
Object
  • Object
show all
Defined in:
lib/af_elastic.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.big_mapObject

Returns the value of attribute big_map.



37
38
39
# File 'lib/af_elastic.rb', line 37

def big_map
  @big_map
end

.eventsObject

Returns the value of attribute events.



35
36
37
# File 'lib/af_elastic.rb', line 35

def events
  @events
end

.typesObject

Returns the value of attribute types.



36
37
38
# File 'lib/af_elastic.rb', line 36

def types
  @types
end

Class Method Details

.add_event(type, data = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/af_elastic.rb', line 62

def add_event(type, data={})
    begin
  	@types ||= Set.new
      @types << type
  	@events ||= []
  	# add timestamp
  	data['timestamp'] = Time.now.to_i
  	@events << {_index: AfElastic.configuration.index, _type: type, _source: data}
    rescue Exception => e
      puts e
      Rails.logger.error("AfElastic::EventReporter::add_event: something wrong with elasticsearch")
    end
end

.cache_event(uniqueKey, type, data = {}) ⇒ Object



39
40
41
42
43
# File 'lib/af_elastic.rb', line 39

def cache_event(uniqueKey, type, data={})
  @big_map ||= {}
  data[:eventType00] = type
  @big_map[uniqueKey] = data
end

.update_event(finalized, uniqueKey, updated_data = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/af_elastic.rb', line 45

def update_event(finalized, uniqueKey, updated_data={})
  if @big_map and @big_map.has_key? uniqueKey
    updated_data.each do |k,v|
      if k != :duration
        @big_map[uniqueKey][k] = v
      else
        @big_map[uniqueKey][:duration] = updated_data[:duration] - @big_map[uniqueKey][:duration]
      end
    end
    if finalized
      type = @big_map[uniqueKey].delete(:eventType00)
      add_event(type, @big_map[uniqueKey])
      @big_map.delete(uniqueKey)
    end
  end
end