Module: Arthropod::Client
- Defined in:
- lib/arthropod/client.rb
Defined Under Namespace
Classes: ServerError
Class Method Summary collapse
Class Method Details
.push(queue_name:, body:, client: nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/arthropod/client.rb', line 8 def self.push(queue_name:, body:, client: nil) client ||= Aws::SQS::Client.new sender_queue = client.create_queue(queue_name: queue_name) return_queue = client.create_queue(queue_name: SecureRandom.uuid.gsub("-", "_")) # Send our order with a return queue so we can get responses client.(queue_url: sender_queue.queue_url, message_body: JSON.dump({ return_queue_url: return_queue.queue_url, body: body })) loop do response = client.(queue_url: return_queue.queue_url, max_number_of_messages: 1, wait_time_seconds: 20) response..each do || response = Arthropod::Response.new(client: client, message: ) begin if response.state == "close" return response elsif response.state == "error" raise Arthropod::Client::ServerError else yield response if block_given? end ensure client.(queue_url: return_queue.queue_url, receipt_handle: .receipt_handle) end end end ensure client.delete_queue(queue_url: return_queue.queue_url) if return_queue end |