Class: KaeruEra::AsyncReporter
- Inherits:
-
Object
- Object
- KaeruEra::AsyncReporter
- Defined in:
- lib/kaeruera/async_reporter.rb
Overview
AsyncReporter reports the error to a KaeruEra application via HTTP, but does it asynchronously.
Instance Method Summary collapse
-
#initialize(url, application_id, token) ⇒ AsyncReporter
constructor
Accepts the same arguments as Reporter.
-
#report(opts = {}) ⇒ Object
If an error cannot be determined, returns false.
Constructor Details
#initialize(url, application_id, token) ⇒ AsyncReporter
Accepts the same arguments as Reporter.
9 10 11 12 13 14 15 |
# File 'lib/kaeruera/async_reporter.rb', line 9 def initialize(url, application_id, token) reporter = Reporter.new(url, application_id, token) @queue = Queue.new Thread.new do loop{reporter.report(@queue.pop) rescue nil} end end |
Instance Method Details
#report(opts = {}) ⇒ Object
If an error cannot be determined, returns false. Otherwise, adds the error to the queue of errors to handle asynchronously and returns true. If an exception would be raised by this code, returns the exception instead of raising it.
Supports the same options as Reporter#report.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/kaeruera/async_reporter.rb', line 24 def report(opts={}) unless opts[:error] return false unless $! opts = opts.merge(:error=>$!) end @queue.push(opts) true rescue => e e end |