Module: EndPointBlank::Commands::Http

Defined in:
lib/end_point_blank/commands/http.rb

Constant Summary collapse

MAX_ATTEMPTS =
3
RETRY_DELAY =
0.2
CONNECT_TIMEOUT =

Per-attempt timeouts (seconds). Kept short because every call site in this lib is fire-and-forget telemetry: a slow/unreachable intake must never block the host application's request thread.

3
READ_TIMEOUT =
5
TIMEOUT_OPTIONS =

Shared Excon options so the timeout values live in exactly one place. Merge this into any Excon.post/Excon.new call in the lib.

{ connect_timeout: CONNECT_TIMEOUT, read_timeout: READ_TIMEOUT }.freeze

Class Method Summary collapse

Class Method Details

.post(url, auth, body) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/end_point_blank/commands/http.rb', line 19

def self.post(url, auth, body)
  attempt = 0
  begin
    attempt += 1
    Excon.post(
      url,
      headers: { 'Authorization' => auth, 'Content-Type' => 'application/json' },
      body: body.to_json,
      **TIMEOUT_OPTIONS
    )
  rescue Excon::Error => e
    # Excon::Error::Timeout (raised for both connect_timeout and
    # read_timeout) is a subclass of Excon::Error, so it is handled
    # here the same as any other transport error: retried, then
    # swallowed with a log line rather than raised to the caller.
    if attempt < MAX_ATTEMPTS
      sleep RETRY_DELAY
      retry
    end
    EndPointBlank.logger.error \
      "[EndPointBlank] HTTP POST to #{url} failed after #{MAX_ATTEMPTS} attempts: #{e.message}"
    nil
  end
end