Class: PatientHttp::SolidQueue::Context
- Inherits:
-
Object
- Object
- PatientHttp::SolidQueue::Context
- Defined in:
- lib/patient_http/solid_queue/context.rb
Overview
Provides thread-safe context for Active Jobs.
Manages the current Active Job context using a thread-id keyed hash, allowing async HTTP requests to access job information without it being passed explicitly. Only RequestJob needs this context for re-enqueueing jobs.
Class Method Summary collapse
-
.current_job ⇒ Hash?
Returns the current job data hash for the running thread.
-
.with_job(job_data) { ... } ⇒ Object
Set the current job context for the duration of a block.
Class Method Details
.current_job ⇒ Hash?
Returns the current job data hash for the running thread.
17 18 19 |
# File 'lib/patient_http/solid_queue/context.rb', line 17 def current_job @jobs[Thread.current.object_id] end |
.with_job(job_data) { ... } ⇒ Object
Set the current job context for the duration of a block.
25 26 27 28 29 30 31 32 |
# File 'lib/patient_http/solid_queue/context.rb', line 25 def with_job(job_data) thread_id = Thread.current.object_id previous_job = @jobs[thread_id] @jobs[thread_id] = job_data yield ensure previous_job ? @jobs[thread_id] = previous_job : @jobs.delete(thread_id) end |