Sha256: 7966a891480f859140be3967a3d38e182f27517eaf4c3059f0cf9d9174444cbe

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module DispatchRider
  module QueueServices
    class AwsSqs < Base
      class SqsReceivedMessage < ReceivedMessage
        attr_reader :total_timeout, :start_time

        def initialize(message, raw_item, queue, queue_visibility_timeout)
          @queue = queue
          @total_timeout = queue_visibility_timeout.to_i
          @start_time = Time.now
          super(message, raw_item)
        end

        # NOTE: Setting the visibility timeout resets the timeout to NOW and makes it visibility timeout this time
        # Essentially resetting the timer on this message
        def extend_timeout(timeout)
          item.change_visibility({
            visibility_timeout: timeout # required
          })
          @total_timeout = timeout + (Time.now - start_time).to_i if timeout > 0
        end

        # We effectively return the item to the queue by setting
        # the visibility timeout to zero.  The item
        # should become immediately visible.
        # The next receiver will reset the visibility
        # to something appropriate
        def return_to_queue
          extend_timeout(0)
        end

        def receive_count
          @item.approximate_receive_count
        end

        def sent_at
          @item.sent_timestamp
        end

        def queue_name
          @item.queue_arn.split(':').last
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dispatch-rider-2.2.0 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb