Class: Yeller::Client
- Inherits:
-
Object
- Object
- Yeller::Client
- Defined in:
- lib/yeller/client.rb
Instance Attribute Summary collapse
-
#backtrace_filter ⇒ Object
readonly
Returns the value of attribute backtrace_filter.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#initialize(servers, token, startup_params, backtrace_filter, error_handler, skip_exceptions) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
- #record_deploy(revision, user, environment) ⇒ Object
- #report(exception, options = {}) ⇒ Object
- #report_with_roundtrip(serialized, error_count) ⇒ Object
- #reported_error? ⇒ Boolean
Constructor Details
#initialize(servers, token, startup_params, backtrace_filter, error_handler, skip_exceptions) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/yeller/client.rb', line 5 def initialize(servers, token, startup_params, backtrace_filter, error_handler, skip_exceptions) @servers = servers @last_server = rand(servers.size) @startup_params = startup_params @token = token @backtrace_filter = backtrace_filter @error_handler = error_handler @skip_exceptions = skip_exceptions @reported_error = false @headers = { "Content-Type" => "application/json", "User-Agent" => @startup_params.fetch(:"client-version") } end |
Instance Attribute Details
#backtrace_filter ⇒ Object (readonly)
Returns the value of attribute backtrace_filter.
3 4 5 |
# File 'lib/yeller/client.rb', line 3 def backtrace_filter @backtrace_filter end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
3 4 5 |
# File 'lib/yeller/client.rb', line 3 def token @token end |
Instance Method Details
#enabled? ⇒ Boolean
53 54 55 |
# File 'lib/yeller/client.rb', line 53 def enabled? true end |
#inspect ⇒ Object
61 62 63 |
# File 'lib/yeller/client.rb', line 61 def inspect "#<Yeller::Client enabled=true token=#{@token.inspect}>" end |
#record_deploy(revision, user, environment) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/yeller/client.rb', line 45 def record_deploy(revision, user, environment) post = Net::HTTP::Post.new("/#{@token}/deploys") post.set_form_data('revision' => revision, 'user' => user, 'environment' => environment) next_server.client.request(post) end |
#report(exception, options = {}) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/yeller/client.rb', line 20 def report(exception, ={}) unless @skip_exceptions.skip?(exception) hash = ExceptionFormatter.format(exception, backtrace_filter, ) serialized = JSON.dump(@startup_params.merge(hash)) report_with_roundtrip(serialized, 0) end end |
#report_with_roundtrip(serialized, error_count) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/yeller/client.rb', line 28 def report_with_roundtrip(serialized, error_count) response = next_server.client.post("/#{@token}", serialized, @headers) if response.code.to_i >= 200 && response.code.to_i <= 300 Yeller::VerifyLog.reported_to_api! @reported_error ||= true else Yeller::VerifyLog.error_code_from_api!(response) end rescue StandardError => e if error_count <= (@servers.size * 2) report_with_roundtrip(serialized, error_count + 1) else Yeller::VerifyLog.exception_from_api!(e) @error_handler.handle(e) end end |
#reported_error? ⇒ Boolean
57 58 59 |
# File 'lib/yeller/client.rb', line 57 def reported_error? @reported_error end |