Module: Shoryuken::ActiveJob::CurrentAttributes::Loading
- Defined in:
- lib/shoryuken/active_job/current_attributes.rb
Overview
Module prepended to JobWrapper to restore CurrentAttributes on execute.
Instance Method Summary collapse
-
#perform(sqs_msg, hash) ⇒ void
Performs the job after restoring CurrentAttributes.
Instance Method Details
#perform(sqs_msg, hash) ⇒ void
This method returns an undefined value.
Performs the job after restoring CurrentAttributes
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/shoryuken/active_job/current_attributes.rb', line 111 def perform(sqs_msg, hash) klasses_to_reset = [] CurrentAttributes.cattrs&.each do |key, klass_name| next unless hash.key?(key) klass = klass_name.constantize klasses_to_reset << klass begin attrs = Serializer.deserialize(hash[key]) attrs.each do |attr_name, value| klass.public_send(:"#{attr_name}=", value) if klass.respond_to?(:"#{attr_name}=") end rescue => e # Log but don't fail if attributes can't be restored # (e.g., attribute removed between enqueue and execute) Shoryuken.logger.warn("Failed to restore CurrentAttributes #{klass_name}: #{e.}") end end super ensure klasses_to_reset.each(&:reset) end |