Class: ActiveJob::QueueAdapters::ShoryukenLaterAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/shoryuken/later/active_job_adapter.rb

Overview

Shoryuken::Later adapter for Active Job

Shoryuken (“sho-ryu-ken”) is a super-efficient AWS SQS thread based message processor. Shoryuken::Later allows messages to be delayed arbitrarily far into the future.

Read more about Shoryuken here. Read more about Shoryuken::Later here.

To use Shoryuken::Later set the queue_adapter config to :shoryuken_later.

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

Defined Under Namespace

Classes: JobWrapper

Class Method Summary collapse

Class Method Details

.enqueue(job) ⇒ Object

:nodoc:



25
26
27
28
29
# File 'lib/shoryuken/later/active_job_adapter.rb', line 25

def enqueue(job) #:nodoc:
  register_worker!(job)

  Shoryuken::Client.send_message(job.queue_name, job.serialize, message_attributes: message_attributes)
end

.enqueue_at(job, timestamp) ⇒ Object

:nodoc:



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/shoryuken/later/active_job_adapter.rb', line 31

def enqueue_at(job, timestamp) #:nodoc:
  register_worker!(job)

  delay = (timestamp - Time.current.to_f).round
  if delay > 15.minutes
    Shoryuken::Later::Client.put_item(Shoryuken::Later.default_table, perform_at: Time.current.to_i + delay.to_i,
                                                                      shoryuken_queue: job.queue_name, shoryuken_class: JobWrapper.to_s,
                                                                      shoryuken_args: JSON.dump(body: job.serialize, options: {}))
  else
    Shoryuken::Client.send_message(job.queue_name, job.serialize, delay_seconds: delay,
                                                                  message_attributes: message_attributes)
  end
end