Class: Opener::Daemons::SQS
- Inherits:
-
Object
- Object
- Opener::Daemons::SQS
- Defined in:
- lib/opener/daemons/sqs.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sqs ⇒ Object
readonly
Returns the value of attribute sqs.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #delete_message(handle) ⇒ Object
-
#initialize(name) ⇒ SQS
constructor
A new instance of SQS.
- #queue_url ⇒ Object
- #receive_messages(limit) ⇒ Object
- #send_message(message) ⇒ Object
- #to_hash(messages) ⇒ Object
Constructor Details
#initialize(name) ⇒ SQS
Returns a new instance of SQS.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/opener/daemons/sqs.rb', line 12 def initialize(name) @sqs = Aws::SQS::Client.new @name = name begin @url = sqs.get_queue_url(:queue_name=>name)[:queue_url] rescue Aws::SQS::Errors::NonExistentQueue => e sqs.create_queue(:queue_name=>name) retry end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/opener/daemons/sqs.rb', line 6 def name @name end |
#sqs ⇒ Object (readonly)
Returns the value of attribute sqs.
6 7 8 |
# File 'lib/opener/daemons/sqs.rb', line 6 def sqs @sqs end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/opener/daemons/sqs.rb', line 6 def url @url end |
Class Method Details
.find(name) ⇒ Object
8 9 10 |
# File 'lib/opener/daemons/sqs.rb', line 8 def self.find(name) new(name) end |
Instance Method Details
#delete_message(handle) ⇒ Object
27 28 29 |
# File 'lib/opener/daemons/sqs.rb', line 27 def (handle) sqs.(:queue_url=>url, :receipt_handle=>handle) end |
#queue_url ⇒ Object
48 49 50 |
# File 'lib/opener/daemons/sqs.rb', line 48 def queue_url url end |
#receive_messages(limit) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/opener/daemons/sqs.rb', line 31 def (limit) result = sqs.(:queue_url=>url, :max_number_of_messages=>limit)[:messages] rescue [] result ? to_hash(result) : [] end |
#send_message(message) ⇒ Object
23 24 25 |
# File 'lib/opener/daemons/sqs.rb', line 23 def () sqs.(:queue_url=>url, :message_body=>) end |
#to_hash(messages) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/opener/daemons/sqs.rb', line 39 def to_hash() .map do |m| hash = m.to_hash json_body = JSON.parse(hash.delete(:body)) hash[:body] = json_body["body"] ? json_body["body"] : json_body hash end end |