Class: AfElastic::EventReporter

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

Class Method Summary collapse

Class Method Details

.report_eventsObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/af_elastic.rb', line 81

def report_events
	events_to_report = AfElastic::EventStore.events || []
	return if events_to_report.length < AfElastic.configuration.capacity
	AfElastic::EventStore.events = []

	th = Thread.new do 
	  begin
        Timeout::timeout(3) {
          uri = URI.parse(AfElastic.configuration.flask)
          params = {credential: "kqjD93ZJoSkAVNW0pjTqrVNubLCLK3pP", 
                    types: AfElastic::EventStore.types.to_a,
                    index: AfElastic.configuration.index,
                    data: events_to_report}
          header = {"Content-Type" => "application/json"}
          http = Net::HTTP.new(uri.host, uri.port)
          response = http.post(uri.path, params.to_json, header)
        }
		rescue Exception => e
        puts e
			Rails.logger.error("AfElastic::EventReporter::report_events: error doing bulk inserting")
		end  				
	end
    return th
end