lib/app_monit/event.rb in app_monit-0.0.8 vs lib/app_monit/event.rb in app_monit-0.0.9
- old
+ new
@@ -5,11 +5,11 @@
def self.create(*args)
create!(*args)
rescue Http::Error
false
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse,
- Net::HTTPHeaderSyntaxError, Net::ProtocolError => error
+ Net::HTTPHeaderSyntaxError, Net::ProtocolError, Errno::ETIMEDOUT => error
raise error unless AppMonit::Config.fail_silent
false
end
def self.create!(name, data_hash = {})
@@ -21,10 +21,19 @@
message[:api_key] = data_hash.delete(:api_key) if data_hash[:api_key]
message[:environment] = data_hash.delete(:environment) if data_hash[:environment]
message[:payload] = data_hash
- client.post('/v1/events', message)
+ post(message)
+ end
+
+ def self.post(message)
+ if AppMonit::Config.async?
+ AppMonit.logger.debug("[Event] push: #{message}")
+ AppMonit::Worker.instance.push(message)
+ else
+ client.post('/v1/events', message)
+ end
end
def self.client
Http
end