Sha256: 420b26093949a1a26d83cb1f3bd6eee63410ffcc420c6aa57f35e7176d036475

Contents?: true

Size: 940 Bytes

Versions: 58

Compression:

Stored size: 940 Bytes

Contents

# frozen_string_literal: true

module Karafka
  module ActiveJob
    module CurrentAttributes
      # Module expanding the job deserialization to extract current attributes and load them
      # for the time of the job execution
      module Loading
        # @param job_message [Karafka::Messages::Message] message with active job
        def with_deserialized_job(job_message)
          super(job_message) do |job|
            resetable = []

            _cattr_klasses.each do |key, cattr_klass_str|
              next unless job.key?(key)

              attributes = job.delete(key)

              cattr_klass = cattr_klass_str.constantize

              attributes.each do |name, value|
                cattr_klass.public_send("#{name}=", value)
              end

              resetable << cattr_klass
            end

            yield(job)

            resetable.each(&:reset)
          end
        end
      end
    end
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
karafka-2.4.17 lib/karafka/active_job/current_attributes/loading.rb
karafka-2.4.16 lib/karafka/active_job/current_attributes/loading.rb
karafka-2.4.15 lib/karafka/active_job/current_attributes/loading.rb
karafka-2.4.14 lib/karafka/active_job/current_attributes/loading.rb
karafka-2.4.13 lib/karafka/active_job/current_attributes/loading.rb
karafka-2.4.12 lib/karafka/active_job/current_attributes/loading.rb
karafka-2.4.11 lib/karafka/active_job/current_attributes/loading.rb
karafka-2.4.10 lib/karafka/active_job/current_attributes/loading.rb
karafka-2.4.9 lib/karafka/active_job/current_attributes/loading.rb
karafka-2.4.8 lib/karafka/active_job/current_attributes/loading.rb
karafka-2.4.7 lib/karafka/active_job/current_attributes/loading.rb
karafka-2.4.6 lib/karafka/active_job/current_attributes/loading.rb
karafka-2.4.5 lib/karafka/active_job/current_attributes/loading.rb
karafka-2.4.4 lib/karafka/active_job/current_attributes/loading.rb
karafka-2.4.3 lib/karafka/active_job/current_attributes/loading.rb
karafka-2.4.0 lib/karafka/active_job/current_attributes/loading.rb
karafka-2.4.0.rc1 lib/karafka/active_job/current_attributes/loading.rb
karafka-2.3.4 lib/karafka/active_job/current_attributes/loading.rb
karafka-2.4.0.beta2 lib/karafka/active_job/current_attributes/loading.rb
karafka-2.4.0.beta1 lib/karafka/active_job/current_attributes/loading.rb