Skip to content

Commit

Permalink
Merge pull request #218 from bensheldon/immutable_job_serialized_params
Browse files Browse the repository at this point in the history
Ensure Job#serialized_params are immutable
  • Loading branch information
bensheldon committed Mar 1, 2021
2 parents 06300e6 + 60cbc26 commit ab22bfb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/good_job/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Job < ActiveRecord::Base

self.table_name = 'good_jobs'.freeze

attr_readonly :serialized_params

# Parse a string representing a group of queues into a more readable data
# structure.
# @return [Hash]
Expand Down
20 changes: 20 additions & 0 deletions spec/lib/good_job/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,26 @@ def perform(result_value = nil, raise_error: false)
expect(error).to be_an_instance_of ExpectedError
end

context 'when there is an retry handler with exhausted attempts' do
before do
ExampleJob.retry_on(ExpectedError, attempts: 1)

original_attr_readonly = described_class._attr_readonly
described_class._attr_readonly = Set.new

good_job.serialized_params["exception_executions"] = { "[ExpectedError]" => 1 }
good_job.save!

described_class._attr_readonly = original_attr_readonly
end

it 'does not modify the good_job serialized params' do
expect do
good_job.perform
end.not_to change { good_job.reload.serialized_params["exception_executions"]["[ExpectedError]"] }
end
end

context 'when error monitoring service intercepts exception' do
before do
# Similar to Sentry monitor's implementation
Expand Down

0 comments on commit ab22bfb

Please sign in to comment.