Class: Yeller::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(servers, token, startup_params, backtrace_filter, error_handler) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
11
12
13
# File 'lib/yeller/client.rb', line 5

def initialize(servers, token, startup_params, backtrace_filter, error_handler)
  @servers = servers
  @last_server = rand(servers.size)
  @startup_params = startup_params
  @token = token
  @error_handler = error_handler
  @backtrace_filter = backtrace_filter
  @reported_error = false
end

Instance Attribute Details

#backtrace_filterObject (readonly)

Returns the value of attribute backtrace_filter.



3
4
5
# File 'lib/yeller/client.rb', line 3

def backtrace_filter
  @backtrace_filter
end

#tokenObject (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

Returns:

  • (Boolean)


46
47
48
# File 'lib/yeller/client.rb', line 46

def enabled?
  true
end

#inspectObject



54
55
56
# File 'lib/yeller/client.rb', line 54

def inspect
  "#<Yeller::Client enabled=true token=#{@token.inspect}>"
end

#record_deploy(revision, user, environment) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/yeller/client.rb', line 38

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



15
16
17
18
19
# File 'lib/yeller/client.rb', line 15

def report(exception, options={})
  hash = ExceptionFormatter.format(exception, backtrace_filter, options)
  serialized = JSON.dump(@startup_params.merge(hash))
  report_with_roundtrip(serialized, 0)
end

#report_with_roundtrip(serialized, error_count) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/yeller/client.rb', line 21

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

Returns:

  • (Boolean)


50
51
52
# File 'lib/yeller/client.rb', line 50

def reported_error?
  @reported_error
end