Class: ActiveJob::QueueAdapters::SqewerAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/sqewer/extensions/active_job_adapter.rb

Overview

Handle Rails ActiveJob through sqewer. Set it up like so:

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

Defined Under Namespace

Classes: Performable

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.enqueue(active_job) ⇒ Object

:nodoc:



72
73
74
75
76
# File 'lib/sqewer/extensions/active_job_adapter.rb', line 72

def self.enqueue(active_job) #:nodoc:
  wrapped_job = Performable.from_active_job(active_job)

  Sqewer.submit!(wrapped_job)
end

.enqueue_at(active_job, timestamp) ⇒ Object

:nodoc:



78
79
80
81
82
83
84
# File 'lib/sqewer/extensions/active_job_adapter.rb', line 78

def self.enqueue_at(active_job, timestamp) #:nodoc:
  wrapped_job = Performable.from_active_job(active_job)

  delta_t = (timestamp - Time.now.to_i).to_i

  Sqewer.submit!(wrapped_job, delay_seconds: delta_t)
end

Instance Method Details

#enqueue(*args) ⇒ Object



98
99
100
# File 'lib/sqewer/extensions/active_job_adapter.rb', line 98

def enqueue(*args)
  self.class.enqueue(*args)
end

#enqueue_at(*args) ⇒ Object

ActiveJob in Rails 4 resolves the symbol value you give it and then tries to call enqueue_* methods directly on what got resolved. In Rails 5, first Rails will call .new on what it resolved from the symbol and then call enqueue and enqueue_at on that what has gotten resolved. This means that we have to expose these methods both as class methods and as instance methods. This can be removed when we stop supporting Rails 4.



94
95
96
# File 'lib/sqewer/extensions/active_job_adapter.rb', line 94

def enqueue_at(*args)
  self.class.enqueue_at(*args)
end