Sha256: d7fca3bc65c72806eb634ccd4c53f752d2de858e8379df4a4ea02dee03e5bc06

Contents?: true

Size: 1.87 KB

Versions: 20

Compression:

Stored size: 1.87 KB

Contents

# frozen_string_literal: true

require "que"

module ActiveJob
  module QueueAdapters
    # == Que adapter for Active Job
    #
    # Que is a high-performance alternative to DelayedJob or QueueClassic that
    # improves the reliability of your application by protecting your jobs with
    # the same ACID guarantees as the rest of your data. Que is a queue for
    # Ruby and PostgreSQL that manages jobs using advisory locks.
    #
    # Read more about Que {here}[https://github.com/chanks/que].
    #
    # To use Que set the queue_adapter config to +:que+.
    #
    #   Rails.application.config.active_job.queue_adapter = :que
    class QueAdapter
      def enqueue(job) # :nodoc:
        job_options = { priority: job.priority, queue: job.queue_name }
        que_job = nil

        if require_job_options_kwarg?
          que_job = JobWrapper.enqueue job.serialize, job_options: job_options
        else
          que_job = JobWrapper.enqueue job.serialize, **job_options
        end

        job.provider_job_id = que_job.attrs["job_id"]
        que_job
      end

      def enqueue_at(job, timestamp) # :nodoc:
        job_options = { priority: job.priority, queue: job.queue_name, run_at: Time.at(timestamp) }
        que_job = nil

        if require_job_options_kwarg?
          que_job = JobWrapper.enqueue job.serialize, job_options: job_options
        else
          que_job = JobWrapper.enqueue job.serialize, **job_options
        end

        job.provider_job_id = que_job.attrs["job_id"]
        que_job
      end

      private
        def require_job_options_kwarg?
          @require_job_options_kwarg ||=
            JobWrapper.method(:enqueue).parameters.any? { |ptype, pname| ptype == :key && pname == :job_options }
        end

        class JobWrapper < Que::Job # :nodoc:
          def run(job_data)
            Base.execute job_data
          end
        end
    end
  end
end

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
activejob-7.0.8.7 lib/active_job/queue_adapters/que_adapter.rb
activejob-7.0.8.6 lib/active_job/queue_adapters/que_adapter.rb
activejob-7.0.8.5 lib/active_job/queue_adapters/que_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/que_adapter.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activejob-7.0.5.1/lib/active_job/queue_adapters/que_adapter.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activejob-7.0.5.1/lib/active_job/queue_adapters/que_adapter.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activejob-7.0.5.1/lib/active_job/queue_adapters/que_adapter.rb
activejob-7.0.8.4 lib/active_job/queue_adapters/que_adapter.rb
activejob-7.0.8.1 lib/active_job/queue_adapters/que_adapter.rb
activejob-7.0.8 lib/active_job/queue_adapters/que_adapter.rb
activejob-7.0.7.2 lib/active_job/queue_adapters/que_adapter.rb
activejob-7.0.7.1 lib/active_job/queue_adapters/que_adapter.rb
activejob-7.0.7 lib/active_job/queue_adapters/que_adapter.rb
activejob-7.0.6 lib/active_job/queue_adapters/que_adapter.rb
activejob-7.0.5.1 lib/active_job/queue_adapters/que_adapter.rb
activejob-7.0.5 lib/active_job/queue_adapters/que_adapter.rb
activejob-7.0.4.3 lib/active_job/queue_adapters/que_adapter.rb
activejob-7.0.4.2 lib/active_job/queue_adapters/que_adapter.rb
activejob-7.0.4.1 lib/active_job/queue_adapters/que_adapter.rb
activejob-7.0.4 lib/active_job/queue_adapters/que_adapter.rb