Class: DeadBro::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(configuration = DeadBro.configuration) ⇒ Client

Returns a new instance of Client.



10
11
12
13
# File 'lib/dead_bro/client.rb', line 10

def initialize(configuration = DeadBro.configuration)
  @configuration = configuration
  @circuit_breaker = create_circuit_breaker
end

Instance Method Details

#post_heartbeatObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dead_bro/client.rb', line 34

def post_heartbeat
  return if @configuration.api_key.nil?

  @configuration.last_heartbeat_attempt_at = Time.now.utc
  body = {event: "heartbeat", payload: {}, sent_at: Time.now.utc.iso8601, revision: @configuration.resolve_deploy_id}

  dispatch_request(
    url: metrics_endpoint_url,
    body: body,
    event_name: "heartbeat",
    apply_settings: true
  )

  nil
end

#post_metric(event_name:, payload:, force: false) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dead_bro/client.rb', line 15

def post_metric(event_name:, payload:, force: false)
  return if @configuration.api_key.nil?
  return unless @configuration.enabled
  return if !force && !@configuration.should_sample?
  return if circuit_open?

  payload = truncate_payload_for_request(payload)
  body = {event: event_name, payload: payload, sent_at: Time.now.utc.iso8601, revision: @configuration.resolve_deploy_id}

  dispatch_request(
    url: metrics_endpoint_url,
    body: body,
    event_name: event_name,
    apply_settings: true
  )

  nil
end

#post_monitor_stats(payload) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/dead_bro/client.rb', line 50

def post_monitor_stats(payload)
  return if @configuration.api_key.nil?
  return unless @configuration.enabled
  return unless @configuration.job_queue_monitoring_enabled
  return if circuit_open?

  body = {payload: payload, sent_at: Time.now.utc.iso8601, revision: @configuration.resolve_deploy_id}

  dispatch_request(
    url: monitor_endpoint_url,
    body: body,
    event_name: nil,
    apply_settings: false
  )

  nil
end