diff --git a/lib/good_job/job.rb b/lib/good_job/job.rb index 5b21d6aa8..7a67f2b88 100644 --- a/lib/good_job/job.rb +++ b/lib/good_job/job.rb @@ -18,8 +18,6 @@ class Job < Object.const_get(GoodJob.active_record_parent_class) self.table_name = 'good_jobs' self.advisory_lockable_column = 'active_job_id' - attr_readonly :serialized_params - # Parse a string representing a group of queues into a more readable data # structure. # @param string [String] Queue string @@ -277,14 +275,14 @@ def executable? # @return [ExecutionResult] def execute - params = serialized_params.merge( - "provider_job_id" => id - ) - GoodJob::CurrentExecution.reset GoodJob::CurrentExecution.good_job = self + + job_data = serialized_params.deep_dup + job_data["provider_job_id"] = id + ActiveSupport::Notifications.instrument("perform_job.good_job", { good_job: self, process_id: GoodJob::CurrentExecution.process_id, thread_name: GoodJob::CurrentExecution.thread_name }) do - value = ActiveJob::Base.execute(params) + value = ActiveJob::Base.execute(job_data) if value.is_a?(Exception) handled_error = value diff --git a/spec/lib/good_job/job_spec.rb b/spec/lib/good_job/job_spec.rb index fd4611b68..0c7b5a97d 100644 --- a/spec/lib/good_job/job_spec.rb +++ b/spec/lib/good_job/job_spec.rb @@ -254,16 +254,11 @@ def perform(result_value = nil, raise_error: false) before do TestJob.retry_on(TestJob::ExpectedError, attempts: 1) - original_attr_readonly = described_class._attr_readonly - described_class._attr_readonly = Set.new - good_job.serialized_params["exception_executions"] = { "[TestJob::ExpectedError]" => 1 } good_job.save! - - described_class._attr_readonly = original_attr_readonly end - it 'does not modify the good_job serialized params' do + it 'does not modify the original good_job serialized params' do expect do good_job.perform end.not_to change { good_job.reload.serialized_params["exception_executions"]["[TestJob::ExpectedError]"] }