Class: Cloudist::Request
- Includes:
- Encoding
- Defined in:
- lib/cloudist/request.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#qobj ⇒ Object
readonly
Returns the value of attribute qobj.
-
#queue_header ⇒ Object
readonly
Returns the value of attribute queue_header.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Instance Method Summary collapse
- #ack ⇒ Object
- #acked? ⇒ Boolean
- #age ⇒ Object
- #channel ⇒ Object
- #ex ⇒ Object
- #expired? ⇒ Boolean
- #for_message ⇒ Object
-
#initialize(queue, encoded_body, queue_header) ⇒ Request
constructor
A new instance of Request.
- #mq ⇒ Object
- #parse_custom_headers(amqp_headers) ⇒ Object
- #q ⇒ Object
- #ttl ⇒ Object
Methods included from Encoding
Constructor Details
#initialize(queue, encoded_body, queue_header) ⇒ Request
Returns a new instance of Request.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/cloudist/request.rb', line 7 def initialize(queue, encoded_body, queue_header) @qobj, @queue_header = queue, queue_header @body = decode(encoded_body) @headers = parse_custom_headers(queue_header) @payload = Cloudist::Payload.new(encoded_body, queue_header.headers.dup) @headers = @payload.headers @start = Time.now.utc.to_f end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
5 6 7 |
# File 'lib/cloudist/request.rb', line 5 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'lib/cloudist/request.rb', line 5 def headers @headers end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
5 6 7 |
# File 'lib/cloudist/request.rb', line 5 def payload @payload end |
#qobj ⇒ Object (readonly)
Returns the value of attribute qobj.
5 6 7 |
# File 'lib/cloudist/request.rb', line 5 def qobj @qobj end |
#queue_header ⇒ Object (readonly)
Returns the value of attribute queue_header.
5 6 7 |
# File 'lib/cloudist/request.rb', line 5 def queue_header @queue_header end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
5 6 7 |
# File 'lib/cloudist/request.rb', line 5 def start @start end |
Instance Method Details
#ack ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/cloudist/request.rb', line 68 def ack return if acked? queue_header.ack @acked = true rescue AMQP::ChannelClosedError => e Cloudist.handle_error(e) end |
#acked? ⇒ Boolean
64 65 66 |
# File 'lib/cloudist/request.rb', line 64 def acked? @acked == true end |
#age ⇒ Object
50 51 52 53 |
# File 'lib/cloudist/request.rb', line 50 def age return -1 unless headers[:published_on] start - headers[:published_on].to_f end |
#channel ⇒ Object
46 47 48 |
# File 'lib/cloudist/request.rb', line 46 def channel mq end |
#ex ⇒ Object
38 39 40 |
# File 'lib/cloudist/request.rb', line 38 def ex qobj.exchange end |
#expired? ⇒ Boolean
59 60 61 62 |
# File 'lib/cloudist/request.rb', line 59 def expired? return false if ttl == -1 age > ttl end |
#for_message ⇒ Object
30 31 32 |
# File 'lib/cloudist/request.rb', line 30 def [body.dup, queue_header.headers.dup] end |
#mq ⇒ Object
42 43 44 |
# File 'lib/cloudist/request.rb', line 42 def mq qobj.channel end |
#parse_custom_headers(amqp_headers) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cloudist/request.rb', line 19 def parse_custom_headers(amqp_headers) h = amqp_headers.headers.dup h[:published_on] = h[:published_on].to_i h[:ttl] = h[:ttl].to_i rescue -1 h[:ttl] = -1 if h[:ttl] == 0 h end |
#q ⇒ Object
34 35 36 |
# File 'lib/cloudist/request.rb', line 34 def q qobj.queue end |
#ttl ⇒ Object
55 56 57 |
# File 'lib/cloudist/request.rb', line 55 def ttl headers[:ttl] || -1 end |