Sha256: 672e583ac9591bac27dcf2e31baa2909a9e5297f45af085a49381b65fffb9c83

Contents?: true

Size: 1.46 KB

Versions: 20

Compression:

Stored size: 1.46 KB

Contents

require "qu"

module ActiveJob
  module QueueAdapters
    # == Qu adapter for Active Job
    #
    # Qu is a Ruby library for queuing and processing background jobs. It is
    # heavily inspired by delayed_job and Resque. Qu was created to overcome
    # some shortcomings in the existing queuing libraries.
    # The advantages of Qu are: Multiple backends (redis, mongo), jobs are
    # requeued when worker is killed, resque-like API.
    #
    # Read more about Qu {here}[https://github.com/bkeepers/qu].
    #
    # To use Qu set the queue_adapter config to +:qu+.
    #
    #   Rails.application.config.active_job.queue_adapter = :qu
    class QuAdapter
      def enqueue(job, *args) #:nodoc:
        qu_job = Qu::Payload.new(klass: JobWrapper, args: [job.serialize]).tap do |payload|
          payload.instance_variable_set(:@queue, job.queue_name)
        end.push

        # qu_job can be nil depending on the configured backend
        job.provider_job_id = qu_job.id unless qu_job.nil?
        qu_job
      end

      def enqueue_at(job, timestamp, *args) #: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 < Qu::Job #:nodoc:
        def initialize(job_data)
          @job_data = job_data
        end

        def perform
          Base.execute @job_data
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
activejob-5.1.7 lib/active_job/queue_adapters/qu_adapter.rb
activejob-5.1.7.rc1 lib/active_job/queue_adapters/qu_adapter.rb
activejob-5.1.6.2 lib/active_job/queue_adapters/qu_adapter.rb
activejob-5.1.6.1 lib/active_job/queue_adapters/qu_adapter.rb
activejob-5.1.6 lib/active_job/queue_adapters/qu_adapter.rb
activejob-5.1.5 lib/active_job/queue_adapters/qu_adapter.rb
activejob-5.1.5.rc1 lib/active_job/queue_adapters/qu_adapter.rb
activejob-5.1.4 lib/active_job/queue_adapters/qu_adapter.rb
activejob-5.1.4.rc1 lib/active_job/queue_adapters/qu_adapter.rb
activejob-5.1.3 lib/active_job/queue_adapters/qu_adapter.rb
activejob-5.1.3.rc3 lib/active_job/queue_adapters/qu_adapter.rb
activejob-5.1.3.rc2 lib/active_job/queue_adapters/qu_adapter.rb
activejob-5.1.3.rc1 lib/active_job/queue_adapters/qu_adapter.rb
activejob-5.1.2 lib/active_job/queue_adapters/qu_adapter.rb
activejob-5.1.2.rc1 lib/active_job/queue_adapters/qu_adapter.rb
activejob-5.1.1 lib/active_job/queue_adapters/qu_adapter.rb
activejob-5.1.0 lib/active_job/queue_adapters/qu_adapter.rb
activejob-5.1.0.rc2 lib/active_job/queue_adapters/qu_adapter.rb
activejob-5.1.0.rc1 lib/active_job/queue_adapters/qu_adapter.rb
activejob-5.1.0.beta1 lib/active_job/queue_adapters/qu_adapter.rb