Class: Laboristo::Queue
- Inherits:
-
Object
- Object
- Laboristo::Queue
- Defined in:
- lib/laboristo.rb
Instance Attribute Summary collapse
-
#sqs ⇒ Object
Returns the value of attribute sqs.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #each(&block) ⇒ Object (also: #pop)
-
#initialize(url) ⇒ Queue
constructor
A new instance of Queue.
- #purge ⇒ Object
- #push(message) ⇒ Object (also: #<<)
Constructor Details
#initialize(url) ⇒ Queue
Returns a new instance of Queue.
9 10 11 12 |
# File 'lib/laboristo.rb', line 9 def initialize(url) @sqs = Aws::SQS::Client.new @url = url end |
Instance Attribute Details
#sqs ⇒ Object
Returns the value of attribute sqs.
7 8 9 |
# File 'lib/laboristo.rb', line 7 def sqs @sqs end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/laboristo.rb', line 6 def url @url end |
Instance Method Details
#each(&block) ⇒ Object Also known as: pop
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/laboristo.rb', line 19 def each(&block) loop do resp = @sqs.(queue_url: @url, attribute_names: ['All'], max_number_of_messages: 10).data.to_hash resp[:messages] && resp[:messages].each do |msg| begin block.call(Base64.decode64 msg[:body]) @sqs.(queue_url: @url, receipt_handle: msg[:receipt_handle]) rescue StandardError => e $stdout.puts "ERROR: Can't process message #{msg[:message_id]}.\n#{e}" end end end end |
#purge ⇒ Object
40 41 42 |
# File 'lib/laboristo.rb', line 40 def purge @sqs.purge_queue(queue_url: @url) end |
#push(message) ⇒ Object Also known as: <<
14 15 16 17 |
# File 'lib/laboristo.rb', line 14 def push() encoded = Base64.encode64() @sqs.(queue_url: @url, message_body: encoded) end |