Skip to content

Commit 2fe1b3e

Browse files
authored
Pass job.id to the executing job as provider_job_id for access within perform() (#529)
* Pass job.id to the executing job as provider_job_id for access within perform() * Use a string instead of a symbol for provider_job_id * Add a test for the provision of provider_job_id within job execution environment
1 parent ca81cc0 commit 2fe1b3e

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

Diff for: app/models/solid_queue/claimed_execution.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def failed_with(error)
9292

9393
private
9494
def execute
95-
ActiveJob::Base.execute(job.arguments)
95+
ActiveJob::Base.execute(job.arguments.merge("provider_job_id" => job.id))
9696
Result.new(true, nil)
9797
rescue Exception => e
9898
Result.new(false, e)

Diff for: test/dummy/app/jobs/provider_job_id_job.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class ProviderJobIdJob < ApplicationJob
2+
def perform
3+
JobBuffer.add "provider_job_id: #{provider_job_id}"
4+
end
5+
end

Diff for: test/models/solid_queue/claimed_execution_test.rb

+8
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ class SolidQueue::ClaimedExecutionTest < ActiveSupport::TestCase
7373
assert job.reload.failed?
7474
end
7575

76+
test "provider_job_id is available within job execution" do
77+
job = ProviderJobIdJob.perform_later
78+
claimed_execution = prepare_and_claim_job job
79+
claimed_execution.perform
80+
81+
assert_equal "provider_job_id: #{job.provider_job_id}", JobBuffer.last_value
82+
end
83+
7684
private
7785
def prepare_and_claim_job(active_job, process: @process)
7886
job = SolidQueue::Job.find_by(active_job_id: active_job.job_id)

0 commit comments

Comments
 (0)