Module: Que::ActiveJob::WrapperExtensions
- Included in:
- ActiveJob::QueueAdapters::QueAdapter::JobWrapper
- Defined in:
- lib/que/active_job/extensions.rb
Overview
A module that we mix into ActiveJob’s wrapper for Que::Job, to maintain backwards-compatibility with internal changes we make.
Instance Method Summary collapse
-
#attrs ⇒ Object
The Rails adapter (built against a pre-1.0 version of this gem) assumes that it can access a job’s id via job.attrs.
- #run(args) ⇒ Object
Instance Method Details
#attrs ⇒ Object
The Rails adapter (built against a pre-1.0 version of this gem) assumes that it can access a job’s id via job.attrs. So, oblige it.
59 60 61 |
# File 'lib/que/active_job/extensions.rb', line 59 def attrs {"job_id" => que_attrs[:id]} end |
#run(args) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/que/active_job/extensions.rb', line 63 def run(args) # Our ActiveJob extensions expect to be able to operate on the actual # job object, but there's no way to access it through ActiveJob. So, # scope it to the current thread. It's a bit messy, but it's the best # option under the circumstances (doesn't require hacking ActiveJob in # any more extensive way). # There's no reason this logic should ever nest, because it wouldn't # make sense to run a worker inside of a job, but even so, assert that # nothing absurd is going on. Que.assert NilClass, Thread.current[:que_current_job] begin Thread.current[:que_current_job] = self # We symbolize the args hash but ActiveJob doesn't like that :/ super(args.deep_stringify_keys) ensure # Also assert that the current job state was only removed now, but # unset the job first so that an assertion failure doesn't mess up # the state any more than it already has. current = Thread.current[:que_current_job] Thread.current[:que_current_job] = nil Que.assert(self, current) end end |