Sha256: 3ac190d2f0311cddbd09ce867cff769b82cf121ab1da05de5977c29baa2d557e

Contents?: true

Size: 1.52 KB

Versions: 108

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

require "delayed_job"

module ActiveJob
  module QueueAdapters
    # == Delayed Job adapter for Active Job
    #
    # Delayed::Job (or DJ) encapsulates the common pattern of asynchronously
    # executing longer tasks in the background. Although DJ can have many
    # storage backends, one of the most used is based on Active Record.
    # Read more about Delayed Job {here}[https://github.com/collectiveidea/delayed_job].
    #
    # To use Delayed Job, set the queue_adapter config to +:delayed_job+.
    #
    #   Rails.application.config.active_job.queue_adapter = :delayed_job
    class DelayedJobAdapter
      def enqueue(job) #:nodoc:
        delayed_job = Delayed::Job.enqueue(JobWrapper.new(job.serialize), queue: job.queue_name, priority: job.priority)
        job.provider_job_id = delayed_job.id
        delayed_job
      end

      def enqueue_at(job, timestamp) #:nodoc:
        delayed_job = Delayed::Job.enqueue(JobWrapper.new(job.serialize), queue: job.queue_name, priority: job.priority, run_at: Time.at(timestamp))
        job.provider_job_id = delayed_job.id
        delayed_job
      end

      class JobWrapper #:nodoc:
        attr_accessor :job_data

        def initialize(job_data)
          @job_data = job_data
        end

        def display_name
          "#{job_data['job_class']} [#{job_data['job_id']}] from DelayedJob(#{job_data['queue_name']}) with arguments: #{job_data['arguments']}"
        end

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

Version data entries

108 entries across 108 versions & 8 rubygems

Version Path
activejob-6.1.7.10 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-6.1.7.9 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-6.1.7.8 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-6.1.7.7 lib/active_job/queue_adapters/delayed_job_adapter.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activejob-6.1.6.1/lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-6.1.7.6 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-6.1.7.5 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-6.1.7.4 lib/active_job/queue_adapters/delayed_job_adapter.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activejob-6.1.6.1/lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-6.1.7.3 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-6.1.7.2 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-6.1.7.1 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-6.0.6.1 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-6.1.7 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-6.0.6 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-6.1.6.1 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-6.0.5.1 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.2.8.1 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.2.8 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-6.0.5 lib/active_job/queue_adapters/delayed_job_adapter.rb