Sha256: 80bda50baf03f115c0e71b77086b242487d56bf454dcba599cbdc5086404a622

Contents?: true

Size: 1.47 KB

Versions: 27

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

module GoodJob
  module ActiveJobExtensions
    # Allows configuring whether GoodJob should emit a NOTIFY event when a job is enqueued.
    # Configuration will apply either globally to the Job Class, or individually to jobs
    # on initial enqueue and subsequent retries.
    #
    # @example
    #   # Include the concern to your job class:
    #   class MyJob < ApplicationJob
    #     include GoodJob::ActiveJobExtensions::NotifyOptions
    #     self.good_job_notify = false
    #   end
    #
    #   # Or, configure jobs individually to not notify:
    #   MyJob.set(good_job_notify: false).perform_later
    #
    module NotifyOptions
      extend ActiveSupport::Concern

      module Prepends
        def enqueue(options = {})
          self.good_job_notify = options[:good_job_notify] if options.key?(:good_job_notify)
          super
        end

        def serialize
          super.tap do |job_data|
            # Only serialize the value if present to reduce the size of the serialized job
            job_data["good_job_notify"] = good_job_notify unless good_job_notify.nil?
          end
        end

        def deserialize(job_data)
          super
          self.good_job_notify = job_data["good_job_notify"]
        end
      end

      included do
        prepend Prepends
        class_attribute :good_job_notify, instance_accessor: false, instance_predicate: false, default: nil
        attr_accessor :good_job_notify
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
good_job-3.30.0 lib/good_job/active_job_extensions/notify_options.rb
good_job-3.29.5 lib/good_job/active_job_extensions/notify_options.rb
good_job-3.29.4 lib/good_job/active_job_extensions/notify_options.rb
good_job-3.29.3 lib/good_job/active_job_extensions/notify_options.rb
good_job-3.28.2 lib/good_job/active_job_extensions/notify_options.rb
good_job-3.28.1 lib/good_job/active_job_extensions/notify_options.rb
good_job-3.28.0 lib/good_job/active_job_extensions/notify_options.rb