Class: PatientHttp::Sidekiq::Context
- Inherits:
-
Object
- Object
- PatientHttp::Sidekiq::Context
- Defined in:
- lib/patient_http/sidekiq/context.rb
Overview
Provides thread-safe context for Sidekiq jobs.
This class manages the current Sidekiq job context using a thread-id keyed hash, allowing async HTTP requests to access job information without it being passed explicitly. Only RequestWorker needs this context for re-enqueueing jobs.
Defined Under Namespace
Classes: Middleware
Class Method Summary collapse
-
.current_job ⇒ Hash?
Returns the current Sidekiq job hash from context.
-
.with_job(job) { ... } ⇒ Object
Sets the current job context for the duration of the block.
Class Method Details
.current_job ⇒ Hash?
Returns the current Sidekiq job hash from context.
37 38 39 |
# File 'lib/patient_http/sidekiq/context.rb', line 37 def current_job @jobs[Thread.current.object_id] end |
.with_job(job) { ... } ⇒ Object
Sets the current job context for the duration of the block.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/patient_http/sidekiq/context.rb', line 46 def with_job(job) thread_id = Thread.current.object_id previous_job = @jobs[thread_id] @jobs[thread_id] = job yield ensure if previous_job @jobs[thread_id] = previous_job else @jobs.delete(thread_id) end end |