Class: Karafka::ActiveJob::CurrentAttributes::JobWrapper
- Inherits:
-
Object
- Object
- Karafka::ActiveJob::CurrentAttributes::JobWrapper
- Defined in:
- lib/karafka/active_job/current_attributes/job_wrapper.rb
Overview
Simple wrapper that presents a job hash with current attributes injected.
This wrapper exists to pass a modified job hash to the deserializer without modifying the original ActiveJob::Base instance. We cannot modify the job instance directly because:
-
Thread safety: Modifying job instances with singleton methods could cause concurrency issues in multi-threaded environments
-
Rails ownership: ActiveJob::Base is a Rails class we don’t control, and monkey-patching it could break with Rails updates
-
Side effects: Modifying the job instance could affect other parts of the application that use the same job object
The wrapper implements only the #serialize method that the Deserializer expects, returning our pre-computed hash with current attributes already injected.
Instance Method Summary collapse
-
#initialize(job_hash) ⇒ JobWrapper
constructor
A new instance of JobWrapper.
-
#serialize ⇒ Hash
Returns the job hash with current attributes injected.
Constructor Details
#initialize(job_hash) ⇒ JobWrapper
32 33 34 |
# File 'lib/karafka/active_job/current_attributes/job_wrapper.rb', line 32 def initialize(job_hash) @job_hash = job_hash end |
Instance Method Details
#serialize ⇒ Hash
Returns the job hash with current attributes injected
39 40 41 |
# File 'lib/karafka/active_job/current_attributes/job_wrapper.rb', line 39 def serialize @job_hash end |