Sha256: a97e4b6d55f1fcff6af26a1b452796a6a96bf955ded22be5b85d487fef6e01b3

Contents?: true

Size: 1.83 KB

Versions: 18

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true

require "delayed_job"
require "active_support/core_ext/string/inflections"

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
          base_name = "#{job_data["job_class"]} [#{job_data["job_id"]}] from DelayedJob(#{job_data["queue_name"]})"

          return base_name unless log_arguments?

          "#{base_name} with arguments: #{job_data["arguments"]}"
        end

        def perform
          Base.execute(job_data)
        end

        private
          def log_arguments?
            job_data["job_class"].constantize.log_arguments?
          rescue NameError
            false
          end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 4 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/activejob-7.1.3.4/lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-7.1.5.1 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-7.1.5 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-7.1.4.2 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-7.1.4.1 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-7.1.4 lib/active_job/queue_adapters/delayed_job_adapter.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activejob-7.1.3.4/lib/active_job/queue_adapters/delayed_job_adapter.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/activejob-7.1.3.4/lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-7.1.3.4 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-7.1.3.2 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-7.1.3.1 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-7.1.3 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-7.1.2 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-7.1.1 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-7.1.0 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-7.1.0.rc2 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-7.1.0.rc1 lib/active_job/queue_adapters/delayed_job_adapter.rb
activejob-7.1.0.beta1 lib/active_job/queue_adapters/delayed_job_adapter.rb