Class: Aws::ActiveJob::SQS::Poller
- Inherits:
-
Object
- Object
- Aws::ActiveJob::SQS::Poller
- Defined in:
- lib/aws/active_job/sqs/poller.rb
Overview
CLI runner for polling for SQS ActiveJobs Use ‘aws_sqs_active_job –help` for detailed usage
Defined Under Namespace
Classes: Interrupt
Constant Summary collapse
- DEFAULT_OPTS =
{ threads: 2 * Concurrent.processor_count, max_messages: 10, shutdown_timeout: 15, backpressure: 10, retry_standard_errors: true }.freeze
Instance Method Summary collapse
-
#initialize(args = ARGV) ⇒ Poller
constructor
A new instance of Poller.
- #run ⇒ Object
- #set_environment ⇒ Object
Constructor Details
#initialize(args = ARGV) ⇒ Poller
Returns a new instance of Poller.
23 24 25 26 27 |
# File 'lib/aws/active_job/sqs/poller.rb', line 23 def initialize(args = ARGV) @options = parse_args(args) # Set_environment must be run before we boot_rails set_environment end |
Instance Method Details
#run ⇒ Object
33 34 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 60 61 |
# File 'lib/aws/active_job/sqs/poller.rb', line 33 def run # exit 0 boot_rails # cannot load config (from file or initializers) until after # rails has been booted. @options = DEFAULT_OPTS .merge(Aws::ActiveJob::SQS.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], retry_standard_errors: @options[:retry_standard_errors] ) poll rescue Interrupt @logger.info 'Process Interrupted or killed - attempting to shutdown cleanly.' shutdown exit end |
#set_environment ⇒ Object
29 30 31 |
# File 'lib/aws/active_job/sqs/poller.rb', line 29 def set_environment @environment = @options[:environment] || ENV['APP_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development' end |