Sha256: 69469e89dc96f73938885fe564843993e27c25354c395f41f11dc377ec7e4b74

Contents?: true

Size: 867 Bytes

Versions: 1

Compression:

Stored size: 867 Bytes

Contents

module Cloudist
  class Request
    attr_reader :queue_header, :qobj, :payload, :start, :headers

    def initialize(queue, json_encoded_message, queue_header)
      @qobj, @queue_header = queue, queue_header

      @payload = Cloudist::Payload.new(json_encoded_message.dup, queue_header.properties.dup)
      @headers = @payload.parse_custom_headers
      
      @start = Time.now.utc.to_i
    end

    def q
      qobj.q
    end

    def ex
      qobj.ex
    end

    def mq
      qobj.mq
    end

    def age
      return -1 unless headers[:published_on]
      start - headers[:published_on]
    end

    def ttl
      headers[:ttl] || -1
    end

    def expired?
      return false if ttl == -1
      age > ttl
    end

    def acked?
      @acked == true
    end

    def ack
      return if acked?
      queue_header.ack
      @acked = true
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cloudist-0.0.2 lib/cloudist/request.rb