Class: Alplus::Transport

Inherits:
Object
  • Object
show all
Defined in:
lib/alplus/transport.rb

Overview

Sends one envelope to POST /e/errors over Net::HTTP with an explicit open/read timeout. Never raises: every transport failure (timeout, connection refused, 4xx/5xx, an unparseable response) is swallowed and reported as :error/:rejected so the caller (the background worker) can log it without ever propagating into the host app (issue #14 story 8).

Retries a transient failure up to Retry::MAX_ATTEMPTS times with jittered exponential backoff, honoring a 429's Retry-After header (issue #15) — see Retry for the shared loop with Heartbeat. Runs on the existing background Worker thread, never the request thread.

Instance Method Summary collapse

Constructor Details

#initialize(config, sleeper: method(:sleep)) ⇒ Transport

Returns a new instance of Transport.



20
21
22
23
# File 'lib/alplus/transport.rb', line 20

def initialize(config, sleeper: method(:sleep))
  @config = config
  @sleeper = sleeper
end

Instance Method Details

#send_envelope(envelope, kind: :error) ⇒ Object

kind: selects the ingest path (issue #12): :error (default) posts to POST /e/errors, :session to POST /e/sessions. The error envelope's shape and endpoint are unchanged — this is purely additive routing on the same Worker queue/thread.



29
30
31
32
33
34
35
36
# File 'lib/alplus/transport.rb', line 29

def send_envelope(envelope, kind: :error)
  body = JSON.generate(envelope)
  return :oversized if body.bytesize > Envelope::MAX_ENVELOPE_BYTES

  uri = URI.join(@config.endpoint, path_for(kind))
  result = Retry.perform(sleeper: @sleeper) { post(uri, body) }
  outcome(result)
end