Class: ActiveJob::QueueAdapters::ActiveElasticJobAdapter

Inherits:
Object
  • Object
show all
Extended by:
ActiveElasticJob::MD5MessageDigestCalculation
Defined in:
lib/active_job/queue_adapters/active_elastic_job_adapter.rb

Overview

Active Elastic Job adapter for Active Job

Active Elastic Job provides (1) an adapter (this class) for Rails’ Active Job framework and (2) a Rack middleware to process job requests, which are sent by the SQS daemon running in Amazon Elastic Beanstalk worker environments.

This adapter serializes job objects and sends them as a message to an Amazon SQS queue specified by the job’s queue name, see ActiveJob::Base.queue_as

To use Active Elastic Job, set the queue_adapter config to :active_elastic_job.

Rails.application.config.active_job.queue_adapter = :active_elastic_job

Defined Under Namespace

Classes: Error, MD5MismatchError, NonExistentQueue, SerializedJobTooBig

Constant Summary collapse

MAX_MESSAGE_SIZE =
(256 * 1024)

Constants included from ActiveElasticJob::MD5MessageDigestCalculation

ActiveElasticJob::MD5MessageDigestCalculation::CHARSET_ENCODING, ActiveElasticJob::MD5MessageDigestCalculation::TRANSPORT_TYPE_ENCODINGS

Class Method Summary collapse

Methods included from ActiveElasticJob::MD5MessageDigestCalculation

md5_of_message_attributes, md5_of_message_body

Class Method Details

.enqueue(job) ⇒ Object

:nodoc:



73
74
75
# File 'lib/active_job/queue_adapters/active_elastic_job_adapter.rb', line 73

def enqueue(job) #:nodoc:
  enqueue_at(job, Time.now)
end

.enqueue_at(job, timestamp) ⇒ Object

:nodoc:



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/active_job/queue_adapters/active_elastic_job_adapter.rb', line 77

def enqueue_at(job, timestamp) #:nodoc:
  serialized_job = JSON.dump(job.serialize)
  check_job_size!(serialized_job)
  message = build_message(job.queue_name, serialized_job, timestamp)
  resp = aws_sqs_client.send_message(message)
  verify_md5_digests!(
    resp,
    message[:message_body],
    message[:message_attributes]
  )
rescue Aws::SQS::Errors::NonExistentQueue => e
  unless @queue_urls[job.queue_name.to_s].nil?
    @queue_urls[job.queue_name.to_s] = nil
    retry
  end
  raise NonExistentQueue, job
rescue Aws::Errors::ServiceError => e
  raise Error, "Could not enqueue job, #{e.message}"
end