Class: PatientHttp::SolidQueue::Context

Inherits:
Object
  • Object
show all
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

Class Method Details

.current_jobHash?

Returns the current job data hash for the running thread.

Returns:

  • (Hash, nil)


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.

Parameters:

  • job_data (Hash)

    Active Job serialized hash

Yields:



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