Class: Oni::Daemons::SQS

Inherits:
Oni::Daemon show all
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 the poll method of the AWS SQS queue. See the documentation of AWS::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

#workers

Instance Method Summary collapse

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_initializeObject

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_optionsHash

Returns a Hash containing the options to use for the poll method of the SQS queue.

Returns:

  • (Hash)


45
46
47
# File 'lib/oni/daemons/sqs.rb', line 45

def poll_options
  return option(:poll_options, {})
end

#queueAWS::SQS::Queue

Returns the queue to use for the current thread.

:nocov:

Returns:

  • (AWS::SQS::Queue)


55
56
57
# File 'lib/oni/daemons/sqs.rb', line 55

def queue
  return AWS::SQS.new.queues.named(option(:queue_name))
end

#receiveObject

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(poll_options) do |message|
    yield message
  end
end