Class: EzLogsAgent::RetrySender

Inherits:
Object
  • Object
show all
Defined in:
lib/ez_logs_agent/retry_sender.rb

Overview

Retry logic with exponential backoff

Wraps Transport.send(events) with automatic retry logic. Implements exponential backoff with a maximum delay cap.

Responsibilities:

  • Decides IF and WHEN to retry

  • Sleeps between retries using exponential backoff

  • Stops after max attempts

  • Never crashes the host application

Does NOT:

  • Modify events

  • Inspect HTTP status codes

  • Interpret errors

  • Spawn threads

  • Read from or flush Buffer

Constant Summary collapse

MAX_SLEEP_SECONDS =

Maximum sleep duration between retries (hard cap)

5
BASE_DELAY_SECONDS =

Base delay for exponential backoff calculation

0.5

Class Method Summary collapse

Class Method Details

.send(events) ⇒ Symbol

Send events with retry logic

Parameters:

  • events (Array<Hash>)

    Array of event hashes

Returns:

  • (Symbol)

    :success if sent successfully, :failure otherwise



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ez_logs_agent/retry_sender.rb', line 33

def send(events)
  # Empty events is a success (no work to do)
  return :success if events.nil? || events.empty?

  max_attempts = retry_attempts + 1 # Initial attempt + retries
  attempt = 1

  while attempt <= max_attempts
    result = attempt_send(events, attempt, max_attempts)
    return :success if result == :success

    # If this was the last attempt, return failure
    break if attempt >= max_attempts

    # Sleep before next retry
    sleep_before_retry(attempt)
    attempt += 1
  end

  # All attempts exhausted
  log_final_failure(events.size)
  :failure
rescue => error
  # Defensive: if anything unexpected happens, log and return failure
  log_error("[RetrySender] send failed with exception: #{error.class} - #{error.message}")
  :failure
end