Class: Oni::Daemons::SQS
- Inherits:
-
Oni::Daemon
- Object
- Oni::Daemon
- Oni::Daemons::SQS
- Defined in:
- lib/oni/daemons/sqs.rb
Overview
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 thepoll
method of the AWS SQS queue. See the documentation ofAWS::SQS::Queue#poll
for more information on the available options.
Constant Summary
Constants inherited from Oni::Daemon
Oni::Daemon::DEFAULT_THREAD_AMOUNT
Instance Attribute Summary
Attributes inherited from Oni::Daemon
Instance Method Summary collapse
-
#after_initialize ⇒ Object
Checks if the
queue_name
option is set. -
#poll_options ⇒ Hash
Returns a Hash containing the options to use for the
poll
method of the SQS queue. -
#queue ⇒ AWS::SQS::Queue
Returns the queue to use for the current thread.
-
#receive ⇒ Object
Polls an SQS queue for a message and processes it.
Methods inherited from Oni::Daemon
#complete, #create_mapper, #error, #initialize, #process, #run_thread, #run_worker, #spawn_thread, #start, #stop, #threads
Methods included from Configurable
included, #option, #require_option!
Constructor Details
This class inherits a constructor from Oni::Daemon
Instance Method Details
#after_initialize ⇒ Object
Checks if the queue_name
option is set.
26 27 28 |
# File 'lib/oni/daemons/sqs.rb', line 26 def after_initialize require_option!(:queue_name) end |
#poll_options ⇒ Hash
Returns a Hash containing the options to use for the poll
method of
the SQS queue.
45 46 47 |
# File 'lib/oni/daemons/sqs.rb', line 45 def return option(:poll_options, {}) end |
#queue ⇒ AWS::SQS::Queue
Returns the queue to use for the current thread.
:nocov:
55 56 57 |
# File 'lib/oni/daemons/sqs.rb', line 55 def queue return AWS::SQS.new.queues.named(option(:queue_name)) end |
#receive ⇒ Object
Polls an SQS queue for a message and processes it.
33 34 35 36 37 |
# File 'lib/oni/daemons/sqs.rb', line 33 def receive queue.poll() do || yield end end |