Class: EventQ::Amazon::CalculateVisibilityTimeout

Inherits:
Object
  • Object
show all
Defined in:
lib/eventq/eventq_aws/aws_calculate_visibility_timeout.rb

Overview

Class responsible to know how to calculate message Visibility Timeout for Amazon SQS

Instance Method Summary collapse

Constructor Details

#initialize(max_timeout:, logger: EventQ.logger) ⇒ CalculateVisibilityTimeout

Returns a new instance of CalculateVisibilityTimeout.



7
8
9
10
# File 'lib/eventq/eventq_aws/aws_calculate_visibility_timeout.rb', line 7

def initialize(max_timeout:, logger: EventQ.logger)
  @max_timeout = max_timeout
  @logger      = logger
end

Instance Method Details

#call(retry_attempts:, queue_settings:) ⇒ Integer

Calculate Visibility Timeout

Parameters:

  • retry_attempts (Integer)

    Current retry

  • queue_settings (Hash)

    Queue settings

  • allow_retry_back_off (Hash)

    a customizable set of options

  • max_retry_delay (Hash)

    a customizable set of options

  • retry_back_off_grace (Hash)

    a customizable set of options

  • retry_back_off_weight (Hash)

    a customizable set of options

  • retry_delay (Hash)

    a customizable set of options

Returns:

  • (Integer)

    the calculated visibility timeout in seconds



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/eventq/eventq_aws/aws_calculate_visibility_timeout.rb', line 22

def call(retry_attempts:, queue_settings:)
  @retry_attempts       = retry_attempts

  @allow_retry_back_off = queue_settings.fetch(:allow_retry_back_off)
  @max_retry_delay      = queue_settings.fetch(:max_retry_delay)
  @retry_back_off_grace = queue_settings.fetch(:retry_back_off_grace)
  @retry_back_off_weight= queue_settings.fetch(:retry_back_off_weight)
  @retry_delay          = queue_settings.fetch(:retry_delay)

  if @allow_retry_back_off && retry_past_grace_period?
    visibility_timeout = timeout_with_back_off
    visibility_timeout = check_for_max_timeout(visibility_timeout)
  else
    visibility_timeout = timeout_without_back_off
  end

  visibility_timeout
end