Class: Droid::Request
- Inherits:
-
Object
- Object
- Droid::Request
- Defined in:
- lib/droid/request.rb
Instance Attribute Summary collapse
-
#droid_headers ⇒ Object
readonly
Returns the value of attribute droid_headers.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#msg ⇒ Object
(also: #params)
readonly
Returns the value of attribute msg.
-
#qobj ⇒ Object
readonly
Returns the value of attribute qobj.
-
#raw_message ⇒ Object
readonly
Returns the value of attribute raw_message.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Instance Method Summary collapse
- #[](field) ⇒ Object
- #ack ⇒ Object
- #acked? ⇒ Boolean
- #age ⇒ Object
- #data_summary ⇒ Object
- #default_publish_opts ⇒ Object
- #defer(&blk) ⇒ Object
- #ex ⇒ Object
- #expired? ⇒ Boolean
-
#initialize(qobj, header, raw_message) ⇒ Request
constructor
A new instance of Request.
- #mq ⇒ Object
- #publish(name, data, opts = {}, popts = {}, &block) ⇒ Object
- #q ⇒ Object
- #reply(data, opts = {}, popts = {}) ⇒ Object
- #requeue(ropts = {}) ⇒ Object
- #ttl ⇒ Object
Constructor Details
#initialize(qobj, header, raw_message) ⇒ Request
Returns a new instance of Request.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/droid/request.rb', line 10 def initialize(qobj, header, ) @qobj = qobj @header = header @raw_message = @droid_headers = Droid::Utils.parse_custom_headers(header.headers) @msg = Droid::Utils.() @start = Time.now.getgm.to_i @acked = false end |
Instance Attribute Details
#droid_headers ⇒ Object (readonly)
Returns the value of attribute droid_headers.
8 9 10 |
# File 'lib/droid/request.rb', line 8 def droid_headers @droid_headers end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
7 8 9 |
# File 'lib/droid/request.rb', line 7 def header @header end |
#msg ⇒ Object (readonly) Also known as: params
Returns the value of attribute msg.
8 9 10 |
# File 'lib/droid/request.rb', line 8 def msg @msg end |
#qobj ⇒ Object (readonly)
Returns the value of attribute qobj.
7 8 9 |
# File 'lib/droid/request.rb', line 7 def qobj @qobj end |
#raw_message ⇒ Object (readonly)
Returns the value of attribute raw_message.
7 8 9 |
# File 'lib/droid/request.rb', line 7 def @raw_message end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
8 9 10 |
# File 'lib/droid/request.rb', line 8 def start @start end |
Instance Method Details
#[](field) ⇒ Object
35 36 37 |
# File 'lib/droid/request.rb', line 35 def [](field) msg[field.to_s] end |
#ack ⇒ Object
59 60 61 62 63 |
# File 'lib/droid/request.rb', line 59 def ack return if acked? header.ack @acked = true end |
#acked? ⇒ Boolean
55 56 57 |
# File 'lib/droid/request.rb', line 55 def acked? @acked == true end |
#age ⇒ Object
41 42 43 44 |
# File 'lib/droid/request.rb', line 41 def age return -1 unless droid_headers[:published_on] start - droid_headers[:published_on] end |
#data_summary ⇒ Object
105 106 107 |
# File 'lib/droid/request.rb', line 105 def data_summary Droid::Utils.format_data_summary(msg, droid_headers) end |
#default_publish_opts ⇒ Object
99 100 101 102 103 |
# File 'lib/droid/request.rb', line 99 def default_publish_opts { :event_hash => droid_headers[:event_hash] } end |
#defer(&blk) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/droid/request.rb', line 89 def defer(&blk) EM.defer(lambda do begin blk.call rescue => e Droid.handle_error(e) end end) end |
#ex ⇒ Object
27 28 29 |
# File 'lib/droid/request.rb', line 27 def ex qobj.ex end |
#expired? ⇒ Boolean
50 51 52 53 |
# File 'lib/droid/request.rb', line 50 def expired? return false if ttl == -1 age > ttl end |
#mq ⇒ Object
31 32 33 |
# File 'lib/droid/request.rb', line 31 def mq qobj.mq end |
#publish(name, data, opts = {}, popts = {}, &block) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/droid/request.rb', line 72 def publish(name, data, opts={}, popts={}, &block) opts = default_publish_opts.merge(opts) if block raise StandardError, "async publish/reply no longer directly supported... for now." end Droid.publish(name, data, opts, popts) end |
#q ⇒ Object
23 24 25 |
# File 'lib/droid/request.rb', line 23 def q qobj.q end |
#reply(data, opts = {}, popts = {}) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/droid/request.rb', line 65 def reply(data, opts={}, popts={}) opts.merge!(default_publish_opts) reply_to = droid_headers[:reply_to] || self.msg['reply_to'] raise UnknownReplyTo unless reply_to Droid.publish_to_q(reply_to, data, opts, popts) end |
#requeue(ropts = {}) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/droid/request.rb', line 80 def requeue(ropts={}) h = droid_headers.dup h[:requeued] = true h.delete(:ttl) popts = { :headers => h } ropts[:ttl] ||= 10 Droid.publish_to_q(q.name, msg, ropts, popts) end |
#ttl ⇒ Object
46 47 48 |
# File 'lib/droid/request.rb', line 46 def ttl droid_headers[:ttl] || -1 end |