Class: Bugstack::Transport

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

Overview

HTTP transport with background thread and retry logic. Uses stdlib net/http — zero gem dependencies.

Instance Method Summary collapse

Constructor Details

#initialize(endpoint:, api_key:, timeout: 5.0, max_retries: 3, debug: false) ⇒ Transport

Returns a new instance of Transport.



11
12
13
14
15
16
17
18
19
20
# File 'lib/bugstack/transport.rb', line 11

def initialize(endpoint:, api_key:, timeout: 5.0, max_retries: 3, debug: false)
  @endpoint = URI.parse(endpoint)
  @api_key = api_key
  @timeout = timeout
  @max_retries = max_retries
  @debug = debug
  @queue = Queue.new
  @shutdown = false
  @worker = start_worker
end

Instance Method Details

#enqueue(payload) ⇒ Object

Add a payload to the send queue (non-blocking).

Parameters:

  • payload (Hash)


25
26
27
28
29
30
31
# File 'lib/bugstack/transport.rb', line 25

def enqueue(payload)
  return if @shutdown

  @queue << payload
rescue => e
  log_debug("Enqueue failed: #{e.message}")
end

#shutdownObject

Stop the worker thread and wait for it to finish.



34
35
36
37
38
# File 'lib/bugstack/transport.rb', line 34

def shutdown
  @shutdown = true
  @queue << :stop
  @worker&.join(2)
end