Sha256: 6f9931a152d623426e1b2f828eda5b5998c9a49823f86afa0d4b9a05eaec0147

Contents?: true

Size: 1.32 KB

Versions: 20

Compression:

Stored size: 1.32 KB

Contents

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 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/delayed_job_adapter.rb
activejob-5.1.7.rc1 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.1.6.2 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.1.6.1 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.1.6 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.1.5 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.1.5.rc1 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.1.4 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.1.4.rc1 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.1.3 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.1.3.rc3 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.1.3.rc2 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.1.3.rc1 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.1.2 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.1.2.rc1 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.1.1 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.1.0 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.1.0.rc2 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.1.0.rc1 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-5.1.0.beta1 lib/active_job/queue_adapters/delayed_job_adapter.rb