Module: Karafka::ActiveJob::CurrentAttributes
- Defined in:
- lib/karafka/active_job/current_attributes.rb,
lib/karafka/active_job/current_attributes/loading.rb,
lib/karafka/active_job/current_attributes/persistence.rb
Overview
Module that allows to persist current attributes on Karafka jobs
Defined Under Namespace
Modules: Loading, Persistence
Class Method Summary collapse
-
.persist(*klasses) ⇒ Object
Allows for persistence of given current attributes via AJ + Karafka.
Class Method Details
.persist(*klasses) ⇒ Object
Allows for persistence of given current attributes via AJ + Karafka
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/karafka/active_job/current_attributes.rb', line 16 def persist(*klasses) # Support for providing multiple classes klasses = Array(klasses).flatten [Dispatcher, Consumer] .reject { || .respond_to?(:_cattr_klasses) } .each { || .class_attribute :_cattr_klasses, default: {} } # Do not double inject in case of running persist multiple times Dispatcher.prepend(Persistence) unless Dispatcher.ancestors.include?(Persistence) Consumer.prepend(Loading) unless Consumer.ancestors.include?(Loading) klasses.map(&:to_s).each do |stringified_klass| # Prevent registering same klass multiple times next if Dispatcher._cattr_klasses.value?(stringified_klass) key = "cattr_#{Dispatcher._cattr_klasses.count}" Dispatcher._cattr_klasses[key] = stringified_klass Consumer._cattr_klasses[key] = stringified_klass end end |