Sha256: 929157c78d82caa7441a41b742dbaea47026441d847bbb8538dcfa644140fb1a

Contents?: true

Size: 1.43 KB

Versions: 24

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require "sneakers"
require "monitor"

module ActiveJob
  module QueueAdapters
    # = Sneakers adapter for Active Job
    #
    # A high-performance RabbitMQ background processing framework for Ruby.
    # Sneakers is being used in production for both I/O and CPU intensive
    # workloads, and have achieved the goals of high-performance and
    # 0-maintenance, as designed.
    #
    # Read more about Sneakers {here}[https://github.com/jondot/sneakers].
    #
    # To use Sneakers set the queue_adapter config to +:sneakers+.
    #
    #   Rails.application.config.active_job.queue_adapter = :sneakers
    class SneakersAdapter < AbstractAdapter
      def initialize
        @monitor = Monitor.new
      end

      def enqueue(job) # :nodoc:
        @monitor.synchronize do
          JobWrapper.from_queue job.queue_name
          JobWrapper.enqueue ActiveSupport::JSON.encode(job.serialize)
        end
      end

      def enqueue_at(job, timestamp) # :nodoc:
        raise NotImplementedError, "This queueing backend does not support scheduling jobs. To see what features are supported go to http://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html"
      end

      class JobWrapper # :nodoc:
        include Sneakers::Worker
        from_queue "default"

        def work(msg)
          job_data = ActiveSupport::JSON.decode(msg)
          Base.execute job_data
          ack!
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
activejob-8.0.2 lib/active_job/queue_adapters/sneakers_adapter.rb
activejob-8.0.1 lib/active_job/queue_adapters/sneakers_adapter.rb
activejob-8.0.0.1 lib/active_job/queue_adapters/sneakers_adapter.rb
activejob-7.2.2.1 lib/active_job/queue_adapters/sneakers_adapter.rb
activejob-8.0.0 lib/active_job/queue_adapters/sneakers_adapter.rb
activejob-7.2.2 lib/active_job/queue_adapters/sneakers_adapter.rb
activejob-8.0.0.rc2 lib/active_job/queue_adapters/sneakers_adapter.rb
activejob-7.2.1.2 lib/active_job/queue_adapters/sneakers_adapter.rb
activejob-8.0.0.rc1 lib/active_job/queue_adapters/sneakers_adapter.rb
activejob-7.2.1.1 lib/active_job/queue_adapters/sneakers_adapter.rb
activejob-8.0.0.beta1 lib/active_job/queue_adapters/sneakers_adapter.rb
omg-activejob-8.0.0.alpha9 lib/active_job/queue_adapters/sneakers_adapter.rb
omg-activejob-8.0.0.alpha8 lib/active_job/queue_adapters/sneakers_adapter.rb
omg-activejob-8.0.0.alpha7 lib/active_job/queue_adapters/sneakers_adapter.rb
omg-activejob-8.0.0.alpha4 lib/active_job/queue_adapters/sneakers_adapter.rb
omg-activejob-8.0.0.alpha3 lib/active_job/queue_adapters/sneakers_adapter.rb
omg-activejob-8.0.0.alpha2 lib/active_job/queue_adapters/sneakers_adapter.rb
omg-activejob-8.0.0.alpha1 lib/active_job/queue_adapters/sneakers_adapter.rb
activejob-7.2.1 lib/active_job/queue_adapters/sneakers_adapter.rb
activejob-7.2.0 lib/active_job/queue_adapters/sneakers_adapter.rb