Sha256: 1374eb03d531f5fb5d37b56c784979b5fd687d2a1bcbd471dbdcfa425d003fde

Contents?: true

Size: 1.08 KB

Versions: 10

Compression:

Stored size: 1.08 KB

Contents

module Lambdakiq
  class Record

    attr_reader :data

    def initialize(data)
      @data = data
    end

    def body
      data['body']
    end

    def message_id
      data['messageId']
    end

    def receipt_handle
      data['receiptHandle']
    end

    def queue_name
      @queue_name ||= data['eventSourceARN'].split(':').last
    end

    def attributes
      data['attributes']
    end

    def fifo_delay_visibility_timeout
      fifo_delay_seconds - (Time.current - sent_at).to_i
    end

    def fifo_delay_seconds
      data.dig('messageAttributes', 'delay_seconds', 'stringValue').try(:to_i)
    end

    def fifo_delay_seconds?
      fifo_delay_seconds && (sent_at + fifo_delay_seconds).future?
    end

    def sent_at
       @sent_at ||= begin
        ts = attributes['SentTimestamp'].to_i / 1000
        Time.zone ? Time.zone.at(ts) : Time.at(ts)
      end
    end

    def receive_count
      @receive_count ||= attributes['ApproximateReceiveCount'].to_i
    end

    def next_visibility_timeout
      @next_visibility_timeout ||= Backoff.backoff(receive_count)
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
lambdakiq-2.3.0 lib/lambdakiq/record.rb
lambdakiq-2.2.0 lib/lambdakiq/record.rb
lambdakiq-2.1.0 lib/lambdakiq/record.rb
lambdakiq-2.0.2 lib/lambdakiq/record.rb
lambdakiq-2.0.1 lib/lambdakiq/record.rb
lambdakiq-2.0.0 lib/lambdakiq/record.rb
lambdakiq-1.0.4 lib/lambdakiq/record.rb
lambdakiq-1.0.3 lib/lambdakiq/record.rb
lambdakiq-1.0.2 lib/lambdakiq/record.rb
lambdakiq-1.0.1 lib/lambdakiq/record.rb