Class: Aws::Rails::SqsActiveJob::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/rails/sqs_active_job/configuration.rb

Overview

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

Constant Summary collapse

DEFAULTS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Default configuration options

{
  max_messages: 10,
  shutdown_timeout: 15,
  queues: {},
  logger: ::Rails.logger,
  message_group_id: 'SqsActiveJobGroup',
  excluded_deduplication_keys: ['job_id']
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration

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

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :queues (Hash[Symbol, String])

    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.

  • :max_messages (Integer)

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

  • :visibility_timeout (Integer)

    If unset, the visibility timeout configured on the SQS queue will be used. 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)

  • :shutdown_timeout (Integer)

    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.

  • :logger (ActiveSupport::Logger)

    Logger to use for the poller.

  • :config_file (String)

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

  • :message_group_id (String) — default: 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)

  • :async_queue_error_handler (Callable)

    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
  • :client (SQS::Client)

    SQS Client to use. A default client will be created if none is provided.

  • :excluded_deduplication_keys (Array) — default: ['job_id']

    The type of keys stored in the array should be String or Symbol. Using this option, job_id is implicitly added to the keys.



92
93
94
95
96
97
98
# File 'lib/aws/rails/sqs_active_job/configuration.rb', line 92

def initialize(options = {})
  options[:config_file] ||= config_file if File.exist?(config_file)
  options = DEFAULTS
            .merge(file_options(options))
            .merge(options)
  set_attributes(options)
end

Instance Attribute Details

#async_queue_error_handlerObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



35
36
37
# File 'lib/aws/rails/sqs_active_job/configuration.rb', line 35

def async_queue_error_handler
  @async_queue_error_handler
end

#clientObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



35
36
37
# File 'lib/aws/rails/sqs_active_job/configuration.rb', line 35

def client
  @client
end

#excluded_deduplication_keysObject

Returns the value of attribute excluded_deduplication_keys.



39
40
41
# File 'lib/aws/rails/sqs_active_job/configuration.rb', line 39

def excluded_deduplication_keys
  @excluded_deduplication_keys
end

#loggerObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



35
36
37
# File 'lib/aws/rails/sqs_active_job/configuration.rb', line 35

def logger
  @logger
end

#max_messagesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



35
36
37
# File 'lib/aws/rails/sqs_active_job/configuration.rb', line 35

def max_messages
  @max_messages
end

#message_group_idObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



35
36
37
# File 'lib/aws/rails/sqs_active_job/configuration.rb', line 35

def message_group_id
  @message_group_id
end

#queuesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



35
36
37
# File 'lib/aws/rails/sqs_active_job/configuration.rb', line 35

def queues
  @queues
end

#shutdown_timeoutObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



35
36
37
# File 'lib/aws/rails/sqs_active_job/configuration.rb', line 35

def shutdown_timeout
  @shutdown_timeout
end

#visibility_timeoutObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



35
36
37
# File 'lib/aws/rails/sqs_active_job/configuration.rb', line 35

def visibility_timeout
  @visibility_timeout
end

Instance Method Details

#queue_url_for(job_queue) ⇒ Object

Return the queue_url for a given job_queue name

Raises:

  • (ArgumentError)


113
114
115
116
117
118
# File 'lib/aws/rails/sqs_active_job/configuration.rb', line 113

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]
end

#to_hObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



126
127
128
129
130
131
132
133
134
# File 'lib/aws/rails/sqs_active_job/configuration.rb', line 126

def to_h
  h = {}
  instance_variables.each do |v|
    v_sym = v.to_s.gsub('@', '').to_sym
    val = instance_variable_get(v)
    h[v_sym] = val
  end
  h
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



121
122
123
# File 'lib/aws/rails/sqs_active_job/configuration.rb', line 121

def to_s
  to_h.to_s
end