Module: Legion::Extensions::Actors::RetryPolicy

Defined in:
lib/legion/extensions/actors/retry_policy.rb

Constant Summary collapse

DEFAULT_THRESHOLD =
2
RETRY_COUNT_HEADER =
'x-retry-count'

Class Method Summary collapse

Class Method Details

.extract_retry_count(headers) ⇒ Object



18
19
20
21
22
23
# File 'lib/legion/extensions/actors/retry_policy.rb', line 18

def extract_retry_count(headers)
  return 0 if headers.nil?

  count = headers[RETRY_COUNT_HEADER] || headers[RETRY_COUNT_HEADER.to_sym] || 0
  count.to_i
end

.retry_thresholdObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/legion/extensions/actors/retry_policy.rb', line 25

def retry_threshold
  threshold = nil
  if defined?(Legion::Settings)
    threshold = Legion::Settings.dig(:fleet, :poison_message_threshold)
    threshold ||= Legion::Settings.dig(:transport, :retry_threshold)
  end
  threshold || DEFAULT_THRESHOLD
rescue StandardError
  DEFAULT_THRESHOLD
end

.should_retry?(retry_count:, threshold:) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/legion/extensions/actors/retry_policy.rb', line 12

def should_retry?(retry_count:, threshold:)
  return true if threshold.nil?

  retry_count < threshold
end