class Oni::Daemons::SQS
The SQS
daemon is a basic daemon skeleton that can be used to process jobs from an Amazon SQS
queue.
Basic usage:
class MyDaemon < Oni::Daemons::SQS set :queue_name, 'my_queue' end
The following options can be set:
-
`queue_name` (required): the name of the queue to poll as a String.
-
`poll_options`: a Hash of options to pass to the `poll` method of the AWS
SQS
queue. See the documentation of `AWS::SQS::Queue#poll` for more information on the available options.
Public Instance Methods
after_initialize()
click to toggle source
Checks if the `queue_name` option is set.
# File lib/oni/daemons/sqs.rb, line 27 def after_initialize require_option!(:queue_name) end
poll_options()
click to toggle source
Returns a Hash containing the options to use for the `poll` method of the SQS
queue.
@return [Hash]
# File lib/oni/daemons/sqs.rb, line 52 def poll_options return option(:poll_options, {}) end
queue()
click to toggle source
Returns the queue to use for the current thread.
@return [Aws::SQS::QueuePoller]
# File lib/oni/daemons/sqs.rb, line 61 def queue return Aws::SQS::QueuePoller.new(queue_url) end
queue_url()
click to toggle source
@return [String]
# File lib/oni/daemons/sqs.rb, line 68 def queue_url sqs = Aws::SQS::Client.new response = sqs.get_queue_url(:queue_name => option(:queue_name)) return response.queue_url end
receive() { |messages| ... }
click to toggle source
Polls an SQS
queue for a message and processes it.
# File lib/oni/daemons/sqs.rb, line 34 def receive poll_options.merge! max_number_of_messages: 10 queue.poll poll_options do |messages| next yield messages unless messages.is_a? Array messages.each do |message| yield message end end end