Class: ActiveJob::QueueAdapters::SuckerPunchAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- ActiveJob::QueueAdapters::SuckerPunchAdapter
- Defined in:
- lib/active_job/queue_adapters/sucker_punch_adapter.rb
Overview
Sucker Punch adapter for Active Job
Sucker Punch is a single-process Ruby asynchronous processing library. This reduces the cost of hosting on a service like Heroku along with the memory footprint of having to maintain additional jobs if hosting on a dedicated server. All queues can run within a single application (e.g. Rails, Sinatra, etc.) process.
Read more about Sucker Punch here.
To use Sucker Punch set the queue_adapter config to :sucker_punch
.
Rails.application.config.active_job.queue_adapter = :sucker_punch
Defined Under Namespace
Classes: JobWrapper
Instance Method Summary collapse
- #check_adapter ⇒ Object
-
#enqueue(job) ⇒ Object
:nodoc:.
-
#enqueue_at(job, timestamp) ⇒ Object
:nodoc:.
Instance Method Details
#check_adapter ⇒ Object
21 22 23 24 25 26 |
# File 'lib/active_job/queue_adapters/sucker_punch_adapter.rb', line 21 def check_adapter ActiveJob.deprecator.warn <<~MSG.squish The `sucker_punch` adapter is deprecated and will be removed in Rails 8.1. Please use the `async` adapter instead. MSG end |
#enqueue(job) ⇒ Object
:nodoc:
28 29 30 31 32 33 34 35 36 |
# File 'lib/active_job/queue_adapters/sucker_punch_adapter.rb', line 28 def enqueue(job) # :nodoc: if JobWrapper.respond_to?(:perform_async) # sucker_punch 2.0 API JobWrapper.perform_async job.serialize else # sucker_punch 1.0 API JobWrapper.new.async.perform job.serialize end end |
#enqueue_at(job, timestamp) ⇒ Object
:nodoc:
38 39 40 41 42 43 44 45 |
# File 'lib/active_job/queue_adapters/sucker_punch_adapter.rb', line 38 def enqueue_at(job, ) # :nodoc: if JobWrapper.respond_to?(:perform_in) delay = - Time.current.to_f JobWrapper.perform_in delay, job.serialize else raise NotImplementedError, "sucker_punch 1.0 does not support `enqueue_at`. Please upgrade to version ~> 2.0.0 to enable this behavior." end end |