lib/sqewer/extensions/active_job_adapter.rb in sqewer-8.1.0 vs lib/sqewer/extensions/active_job_adapter.rb in sqewer-9.0.0

- old
+ new

@@ -1,16 +1,8 @@ # ActiveJob docs: http://edgeguides.rubyonrails.org/active_job_basics.html # Example adapters ref: https://github.com/rails/rails/tree/master/activejob/lib/active_job/queue_adapters module ActiveJob - # Only prepend the module with keyword argument acceptance when the version is 4 - # ActiveJob 5.x supports kwargs out of the box - if ActiveJob::VERSION::MAJOR <= 4 - module Execution - prepend PerformWithKeywords - end - end - module QueueAdapters # Handle Rails ActiveJob through sqewer. # Set it up like so: # # Rails.application.config.active_job.queue_adapter = :sqewer @@ -54,50 +46,34 @@ with_active_record_connection_from_pool { Base.execute(job) } else Base.execute(job) end end - + private - + def with_active_record_connection_from_pool ActiveRecord::Base.connection_pool.with_connection { yield } end - + def active_record_defined_and_connected? defined?(ActiveRecord) && ActiveRecord::Base.connected? end - + end - def self.enqueue(active_job) #:nodoc: + def enqueue(*args) wrapped_job = Performable.from_active_job(active_job) Sqewer.submit!(wrapped_job) end - def self.enqueue_at(active_job, timestamp) #:nodoc: + def enqueue_at(*args) 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 - - # 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. - def enqueue_at(*args) - self.class.enqueue_at(*args) - end - - def enqueue(*args) - self.class.enqueue(*args) end end end end