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
5 6 7 8 9 10 11 12 13 14 |
# 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 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
49 50 51 |
# File 'lib/yeller/client.rb', line 49 def enabled? true end |
#inspect ⇒ Object
57 58 59 |
# File 'lib/yeller/client.rb', line 57 def inspect "#<Yeller::Client enabled=true token=#{@token.inspect}>" end |
#record_deploy(revision, user, environment) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/yeller/client.rb', line 41 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
16 17 18 19 20 21 22 |
# File 'lib/yeller/client.rb', line 16 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
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/yeller/client.rb', line 24 def report_with_roundtrip(serialized, error_count) response = next_server.client.post("/#{@token}", serialized, {"Content-Type" => "application/json"}) 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
53 54 55 |
# File 'lib/yeller/client.rb', line 53 def reported_error? @reported_error end |