Class: AfElastic::EventStore
- Inherits:
-
Object
- Object
- AfElastic::EventStore
- Defined in:
- lib/af_elastic.rb
Class Attribute Summary collapse
-
.big_map ⇒ Object
Returns the value of attribute big_map.
-
.events ⇒ Object
Returns the value of attribute events.
-
.types ⇒ Object
Returns the value of attribute types.
Class Method Summary collapse
- .add_event(type, data = {}) ⇒ Object
- .cache_event(uniqueKey, type, data = {}) ⇒ Object
- .update_event(finalized, uniqueKey, updated_data = {}) ⇒ Object
Class Attribute Details
.big_map ⇒ Object
Returns the value of attribute big_map.
32 33 34 |
# File 'lib/af_elastic.rb', line 32 def big_map @big_map end |
.events ⇒ Object
Returns the value of attribute events.
30 31 32 |
# File 'lib/af_elastic.rb', line 30 def events @events end |
.types ⇒ Object
Returns the value of attribute types.
31 32 33 |
# File 'lib/af_elastic.rb', line 31 def types @types end |
Class Method Details
.add_event(type, data = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/af_elastic.rb', line 57 def add_event(type, data={}) begin @types ||= Set.new unless @types.include? type puts "new type encountered" # check mapping through network unless AfElastic.configuration.es.indices.exists_type? index: AfElastic.configuration.index, type: type dynamic = [{:simple_def=>{:match=>"*",:match_mapping_type=> "string",:mapping=> {:type=> "string",:index=> "not_analyzed"}}}] map = {} map[type] = {properties:{timestamp:{type:"date"}},dynamic_templates:dynamic} unless AfElastic.configuration.es.indices.exists? index: AfElastic.configuration.index AfElastic.configuration.es.indices.create index: AfElastic.configuration.index end AfElastic.configuration.es.indices.put_mapping index: AfElastic.configuration.index, type: type, body: map end @types.add type end @events ||= [] # add timestamp data['timestamp'] = Time.now.to_i @events << {index: {_index: AfElastic.configuration.index, _type: type, data: data}} rescue Exception => e puts e puts "AfElastic::EventReporter::add_event: something wrong with elasticsearch" end end |
.cache_event(uniqueKey, type, data = {}) ⇒ Object
34 35 36 37 38 |
# File 'lib/af_elastic.rb', line 34 def cache_event(uniqueKey, type, data={}) @big_map ||= {} data[:eventType00] = type @big_map[uniqueKey] = data end |
.update_event(finalized, uniqueKey, updated_data = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/af_elastic.rb', line 40 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 |