class Aws::Rails::SqsActiveJob::Configuration

Configuration for AWS SQS ActiveJob. Use Aws::Rails::SqsActiveJob.config to access the singleton config instance.

Constants

DEFAULTS

Default configuration options @api private

Attributes

async_queue_error_handler[RW]

@api private

client[RW]

@api private

logger[RW]

@api private

max_messages[RW]

@api private

message_group_id[RW]

@api private

queues[RW]

@api private

shutdown_timeout[RW]

@api private

visibility_timeout[RW]

@api private

Public Class Methods

new(options = {}) click to toggle source

Don't use this method directly: Confugration is a singleton class, use Aws::Rails::SqsActiveJob.config to access the singleton config.

@param [Hash] options @option options [Hash[Symbol, String]] :queues A mapping between the

active job queue name and the SQS Queue URL. Note: multiple active
job queues can map to the same SQS Queue URL.

@option options [Integer] :max_messages

The max number of messages to poll for in a batch.

@option options [Integer] :visibility_timeout

The visibility timeout is the number of seconds
that a message will not be processable by any other consumers.
You should set this value to be longer than your expected job runtime
to prevent other processes from picking up an running job.
See the (SQS Visibility Timeout Documentation)[https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html]

@option options [Integer] :shutdown_timeout

the amount of time to wait
for a clean shutdown.  Jobs that are unable to complete in this time
will not be deleted from the SQS queue and will be retryable after
the visibility timeout.

@option options [ActiveSupport::Logger] :logger Logger to use

for the poller.

@option options [String] :config_file

Override file to load configuration from.  If not specified will
attempt to load from config/aws_sqs_active_job.yml.

@option options [String] :message_group_id (SqsActiveJobGroup)

The message_group_id to use for queueing messages on a fifo queues.
Applies only to jobs queued on FIFO queues.
See the (SQS FIFO Documentation)[https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queues.html]

@option options [Callable] :async_queue_error_handler An error handler

to be called when the async active job adapter experiances an error
queueing a job.  Only applies when
+active_job.queue_adapter = :amazon_sqs_async+.  Called with:
[error, job, job_options]

@option options [SQS::Client] :client SQS Client to use. A default

client will be created if none is provided.
# File lib/aws/rails/sqs_active_job/configuration.rb, line 85
def initialize(options = {})
  options[:config_file] ||= config_file if config_file.exist?
  options = DEFAULTS
     .merge(file_options(options))
     .merge(options)
  set_attributes(options)
end

Public Instance Methods

queue_url_for(job_queue) click to toggle source

Return the queue_url for a given job_queue name

# File lib/aws/rails/sqs_active_job/configuration.rb, line 98
def queue_url_for(job_queue)
  job_queue = job_queue.to_sym
  raise ArgumentError, "No queue defined for #{job_queue}" unless queues.key? job_queue

  queues[job_queue.to_sym]
end
to_h() click to toggle source

@api private

# File lib/aws/rails/sqs_active_job/configuration.rb, line 111
def to_h
  h = {}
  self.instance_variables.each do |v|
    v_sym = v.to_s.gsub('@', '').to_sym
    val = self.instance_variable_get(v)
    h[v_sym] = val
  end
  h
end
to_s() click to toggle source

@api private

# File lib/aws/rails/sqs_active_job/configuration.rb, line 106
def to_s
  to_h.to_s
end

Private Instance Methods

config_file() click to toggle source
# File lib/aws/rails/sqs_active_job/configuration.rb, line 139
def config_file
  file = ::Rails.root.join("config/aws_sqs_active_job/#{::Rails.env}.yml")
  file = ::Rails.root.join('config/aws_sqs_active_job.yml') unless file.exist?
  file
end
config_file_path(options) click to toggle source

@return [String] Configuration path found in environment or YAML file.

# File lib/aws/rails/sqs_active_job/configuration.rb, line 153
def config_file_path(options)
  options[:config_file] || ENV["AWS_SQS_ACTIVE_JOB_CONFIG_FILE"]
end
file_options(options = {}) click to toggle source
# File lib/aws/rails/sqs_active_job/configuration.rb, line 130
def file_options(options = {})
  file_path = config_file_path(options)
  if file_path
    load_from_file(file_path)
  else
    {}
  end
end
load_from_file(file_path) click to toggle source

Load options from YAML file

# File lib/aws/rails/sqs_active_job/configuration.rb, line 146
def load_from_file(file_path)
  require "erb"
  opts = YAML.load(ERB.new(File.read(file_path)).result) || {}
  opts.deep_symbolize_keys
end
set_attributes(options) click to toggle source

Set accessible attributes after merged options.

# File lib/aws/rails/sqs_active_job/configuration.rb, line 124
def set_attributes(options)
  options.keys.each do |opt_name|
    instance_variable_set("@#{opt_name}", options[opt_name])
  end
end
user_agent() click to toggle source
# File lib/aws/rails/sqs_active_job/configuration.rb, line 157
def user_agent
  "ft/aws-sdk-rails-activejob/#{Aws::Rails::VERSION}"
end