AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Class: Aws::Rails::SqsActiveJob::Poller

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

Overview

CLI runner for polling for SQS ActiveJobs Use `aws_sqs_active_job –help` for detailed usage

Constant Summary collapse

DEFAULT_OPTS =
{
  threads: 2*Concurrent.processor_count,
  max_messages: 10,
  visibility_timeout: 60,
  shutdown_timeout: 15,
  backpressure: 10
}

Instance Method Summary collapse

Constructor Details

#initialize(args = ARGV) ⇒ Poller

Returns a new instance of Poller.



25
26
27
28
29
# File 'lib/aws/rails/sqs_active_job/poller.rb', line 25

def initialize(args = ARGV)
  @options = parse_args(args)
  # Set_environment must be run before we boot_rails
  set_environment
end

Instance Method Details

#runObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/aws/rails/sqs_active_job/poller.rb', line 35

def run
  # exit 0
  boot_rails

  # cannot load config (from file or initializers) until after
  # rails has been booted.
  @options = DEFAULT_OPTS
             .merge(Aws::Rails::SqsActiveJob.config.to_h)
             .merge(@options.to_h)
  validate_config
  # ensure we have a logger configured
  @logger = @options[:logger] || ActiveSupport::Logger.new(STDOUT)
  @logger.info("Starting Poller with options=#{@options}")


  Signal.trap('INT') { raise Interrupt }
  Signal.trap('TERM') { raise Interrupt }
  @executor = Executor.new(max_threads: @options[:threads], logger: @logger, max_queue: @options[:backpressure])

  poll
rescue Interrupt
  @logger.info 'Process Interrupted or killed - attempting to shutdown cleanly.'
  shutdown
  exit
end

#set_environmentObject



31
32
33
# File 'lib/aws/rails/sqs_active_job/poller.rb', line 31

def set_environment
  @environment = @options[:environment] || ENV["APP_ENV"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
end