Class: ActiveJob::QueueAdapters::SqsAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/active_job/queue_adapters/sqs_adapter.rb,
lib/active_job/queue_adapters/sqs_adapter/params.rb

Overview

Set in rails config via config.active_job.queue_adapter = :sqs to use the SQS adapter

Direct Known Subclasses

SqsAsyncAdapter

Defined Under Namespace

Classes: Params

Instance Method Summary collapse

Instance Method Details

#enqueue(job) ⇒ Object



13
14
15
# File 'lib/active_job/queue_adapters/sqs_adapter.rb', line 13

def enqueue(job)
  _enqueue(job)
end

#enqueue_after_transaction_commit?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/active_job/queue_adapters/sqs_adapter.rb', line 9

def enqueue_after_transaction_commit?
  true
end

#enqueue_all(jobs) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/active_job/queue_adapters/sqs_adapter.rb', line 22

def enqueue_all(jobs)
  enqueued_count = 0
  jobs.group_by(&:queue_name).each do |queue_name, same_queue_jobs|
    queue_url = Aws::Rails::SqsActiveJob.config.queue_url_for(queue_name)
    base_send_message_opts = { queue_url: queue_url }

    same_queue_jobs.each_slice(10) do |chunk|
      entries = chunk.map do |job|
        entry = Params.new(job, nil).entry
        entry[:id] = job.job_id
        entry[:delay_seconds] = Params.assured_delay_seconds(job.scheduled_at) if job.scheduled_at
        entry
      end

      send_message_opts = base_send_message_opts.deep_dup
      send_message_opts[:entries] = entries

      send_message_batch_result = Aws::Rails::SqsActiveJob.config.client.send_message_batch(send_message_opts)
      enqueued_count += send_message_batch_result.successful.count
    end
  end
  enqueued_count
end

#enqueue_at(job, timestamp) ⇒ Object



17
18
19
20
# File 'lib/active_job/queue_adapters/sqs_adapter.rb', line 17

def enqueue_at(job, timestamp)
  delay = Params.assured_delay_seconds(timestamp)
  _enqueue(job, nil, delay_seconds: delay)
end