Sha256: 0f5208c3f0eab818ec17fdc5d4be67fc540793a5e91ea778d38514af5edd6577

Contents?: true

Size: 858 Bytes

Versions: 4

Compression:

Stored size: 858 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.headers.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

4 entries across 4 versions & 1 rubygems

Version Path
cloudist-0.1.2 lib/cloudist/request.rb
cloudist-0.1.1 lib/cloudist/request.rb
cloudist-0.1.0 lib/cloudist/request.rb
cloudist-0.0.3 lib/cloudist/request.rb