Sha256: 4d6f97dbf9c5c6effceea7723f7873296627fa60e2a86570adc98653fc4bd0de

Contents?: true

Size: 1.3 KB

Versions: 31

Compression:

Stored size: 1.3 KB

Contents

module DispatchRider
  module QueueServices
    class AwsSqs < Base
      class SqsReceivedMessage < ReceivedMessage
        attr_reader :total_timeout, :start_time
        
        def initialize(message, raw_item, queue)
          @queue = queue
          @total_timeout = queue.visibility_timeout
          @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.visibility_timeout = timeout
          if timeout > 0
            @total_timeout = timeout + (Time.now - start_time).to_i
          end
        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
          @queue.arn.split(':').last
        end

      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
dispatch-rider-1.9.0 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb
dispatch-rider-1.8.6 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb
dispatch-rider-1.8.5 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb
dispatch-rider-1.8.4 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb
dispatch-rider-1.8.3 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb
dispatch-rider-1.8.2 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb
dispatch-rider-1.8.1 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb
dispatch-rider-1.8.0 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb
dispatch-rider-1.7.2 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb
dispatch-rider-1.7.1 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb
dispatch-rider-1.7.0 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb
dispatch-rider-1.6.2 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb
dispatch-rider-1.6.1 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb
dispatch-rider-1.6.0 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb
dispatch-rider-1.5.3 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb
dispatch-rider-1.5.2 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb
dispatch-rider-1.5.1 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb
dispatch-rider-1.5.0 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb
dispatch-rider-1.4.2 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb
dispatch-rider-1.4.0 lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb