Sha256: ffd9351bb21d30e9f8dfac967dd9eab67c12c4838ee0d17947692d3602afb5a9

Contents?: true

Size: 1.58 KB

Versions: 38

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

require "sucker_punch"

module ActiveJob
  module QueueAdapters
    # == 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}[https://github.com/brandonhilkert/sucker_punch].
    #
    # To use Sucker Punch set the queue_adapter config to +:sucker_punch+.
    #
    #   Rails.application.config.active_job.queue_adapter = :sucker_punch
    class SuckerPunchAdapter
      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

      def enqueue_at(job, timestamp) # :nodoc:
        if JobWrapper.respond_to?(:perform_in)
          delay = timestamp - Time.current.to_f
          JobWrapper.perform_in delay, job.serialize
        else
          raise NotImplementedError, "sucker_punch 1.0 does not support `enqueued_at`. Please upgrade to version ~> 2.0.0 to enable this behavior."
        end
      end

      class JobWrapper # :nodoc:
        include SuckerPunch::Job

        def perform(job_data)
          Base.execute job_data
        end
      end
    end
  end
end

Version data entries

38 entries across 36 versions & 4 rubygems

Version Path
activejob-7.0.8.7 lib/active_job/queue_adapters/sucker_punch_adapter.rb
activejob-7.0.8.6 lib/active_job/queue_adapters/sucker_punch_adapter.rb
activejob-7.0.8.5 lib/active_job/queue_adapters/sucker_punch_adapter.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activejob-7.0.8.4/lib/active_job/queue_adapters/sucker_punch_adapter.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activejob-7.0.5.1/lib/active_job/queue_adapters/sucker_punch_adapter.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activejob-7.0.5.1/lib/active_job/queue_adapters/sucker_punch_adapter.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activejob-7.0.5.1/lib/active_job/queue_adapters/sucker_punch_adapter.rb
activejob-7.0.8.4 lib/active_job/queue_adapters/sucker_punch_adapter.rb
activejob-7.0.8.1 lib/active_job/queue_adapters/sucker_punch_adapter.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activejob-7.0.3.1/lib/active_job/queue_adapters/sucker_punch_adapter.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activejob-7.0.2.3/lib/active_job/queue_adapters/sucker_punch_adapter.rb
activejob-7.0.8 lib/active_job/queue_adapters/sucker_punch_adapter.rb
activejob-7.0.7.2 lib/active_job/queue_adapters/sucker_punch_adapter.rb
activejob-7.0.7.1 lib/active_job/queue_adapters/sucker_punch_adapter.rb
activejob-7.0.7 lib/active_job/queue_adapters/sucker_punch_adapter.rb
activejob-7.0.6 lib/active_job/queue_adapters/sucker_punch_adapter.rb
activejob-7.0.5.1 lib/active_job/queue_adapters/sucker_punch_adapter.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activejob-7.0.2.3/lib/active_job/queue_adapters/sucker_punch_adapter.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activejob-7.0.3.1/lib/active_job/queue_adapters/sucker_punch_adapter.rb
activejob-7.0.5 lib/active_job/queue_adapters/sucker_punch_adapter.rb