Module: Aws::ActiveJob::SQS
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/aws-activejob-sqs.rb,
lib/aws/active_job/sqs/poller.rb,
lib/aws/active_job/sqs/executor.rb,
lib/aws/active_job/sqs/job_runner.rb,
lib/aws/active_job/sqs/configuration.rb,
lib/aws/active_job/sqs/deduplication.rb,
lib/aws/active_job/sqs/lambda_handler.rb
Defined Under Namespace
Modules: ClassMethods Classes: Configuration, Executor, JobRunner, Poller
Constant Summary collapse
- VERSION =
File.read(File.('../VERSION', __dir__)).strip
Class Method Summary collapse
-
.config ⇒ Configuration
The (singleton) Configuration.
- .configure { ... } ⇒ Object
-
.fifo?(queue_url) ⇒ Boolean
True if the queue_url is a FIFO queue.
-
.lambda_job_handler(event:, context:) ⇒ Object
A lambda event handler to run jobs from an SQS queue trigger.
- .on_worker_stop ⇒ Object
Class Method Details
.config ⇒ Configuration
Returns the (singleton) Configuration.
18 19 20 |
# File 'lib/aws-activejob-sqs.rb', line 18 def self.config @config ||= Configuration.new end |
.configure { ... } ⇒ Object
23 24 25 |
# File 'lib/aws-activejob-sqs.rb', line 23 def self.configure yield(config) end |
.fifo?(queue_url) ⇒ Boolean
Returns true if the queue_url is a FIFO queue.
29 30 31 |
# File 'lib/aws-activejob-sqs.rb', line 29 def self.fifo?(queue_url) queue_url.end_with?('.fifo') end |
.lambda_job_handler(event:, context:) ⇒ Object
A lambda event handler to run jobs from an SQS queue trigger. Configure the entrypoint to: config/environment.Aws::ActiveJob::SQS.lambda_job_handler This will load your Rails environment, and then use this method as the handler.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/aws/active_job/sqs/lambda_handler.rb', line 12 def lambda_job_handler(event:, context:) return 'no records to process' unless event['Records'] event['Records'].each do |record| sqs_msg = to_sqs_msg(record) job = Aws::ActiveJob::SQS::JobRunner.new(sqs_msg) puts("Running job: #{job.id}[#{job.class_name}]") job.run sqs_msg.delete end "Processed #{event['Records'].length} jobs." end |