From 6b6400e68b9575678b477727f6622f24e0ca1439 Mon Sep 17 00:00:00 2001 From: Robert Keresnyei Date: Mon, 8 Jan 2024 22:27:25 +0100 Subject: [PATCH 1/5] Non-existent job fix --- app/models/good_job/base_execution.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/good_job/base_execution.rb b/app/models/good_job/base_execution.rb index 351b965e3..808e7acae 100644 --- a/app/models/good_job/base_execution.rb +++ b/app/models/good_job/base_execution.rb @@ -97,9 +97,9 @@ def discrete? def active_job(ignore_deserialization_errors: false) ActiveJob::Base.deserialize(active_job_data).tap do |aj| aj.send(:deserialize_arguments_if_needed) - rescue ActiveJob::DeserializationError - raise unless ignore_deserialization_errors end + rescue ActiveJob::DeserializationError, NameError + raise unless ignore_deserialization_errors end private From 36a59ddf44b52675c8da08e83343020f445e26b5 Mon Sep 17 00:00:00 2001 From: Robert Keresnyei Date: Tue, 9 Jan 2024 21:11:33 +0100 Subject: [PATCH 2/5] Specs --- spec/app/models/good_job/job_spec.rb | 12 ++++++++++++ spec/rails_helper.rb | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/app/models/good_job/job_spec.rb b/spec/app/models/good_job/job_spec.rb index aa6156310..08f9ba09e 100644 --- a/spec/app/models/good_job/job_spec.rb +++ b/spec/app/models/good_job/job_spec.rb @@ -324,6 +324,18 @@ def perform end.to change { job.reload.status }.from(:scheduled).to(:discarded) end end + + context 'when job class does not exist' do + before do + job.update!(serialized_params: { 'job_class' => 'NonExistentJob' }) + end + + it 'ignores the error and discards the job' do + expect do + job.discard_job("Discarded in test") + end.to change { job.reload.status }.from(:scheduled).to(:discarded) + end + end end describe '#force_discard_job' do diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 687f4332b..90dc68e9a 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -47,7 +47,7 @@ end RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_path = Rails.root.join("spec/fixtures") + config.fixture_paths = [Rails.root.join("spec/fixtures")] # RSpec Rails can automatically mix in different behaviours to your tests # based on their file location, for example enabling you to call `get` and From 807702aba585281600fc52083f4d0ed66b09cfc6 Mon Sep 17 00:00:00 2001 From: Robert Keresnyei Date: Tue, 9 Jan 2024 21:18:37 +0100 Subject: [PATCH 3/5] Spelling --- spec/app/models/good_job/job_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/app/models/good_job/job_spec.rb b/spec/app/models/good_job/job_spec.rb index 08f9ba09e..f39d0a2ed 100644 --- a/spec/app/models/good_job/job_spec.rb +++ b/spec/app/models/good_job/job_spec.rb @@ -327,7 +327,7 @@ def perform context 'when job class does not exist' do before do - job.update!(serialized_params: { 'job_class' => 'NonExistentJob' }) + job.update!(serialized_params: { 'job_class' => 'NonexistentJob' }) end it 'ignores the error and discards the job' do From e7df738a5d522d8e4dbb0a3e9e7338e8c58d3bdc Mon Sep 17 00:00:00 2001 From: Robert Keresnyei Date: Tue, 9 Jan 2024 21:33:23 +0100 Subject: [PATCH 4/5] Improve documentation --- app/models/good_job/base_execution.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/good_job/base_execution.rb b/app/models/good_job/base_execution.rb index 808e7acae..f34f0c897 100644 --- a/app/models/good_job/base_execution.rb +++ b/app/models/good_job/base_execution.rb @@ -92,7 +92,7 @@ def discrete? # Build an ActiveJob instance and deserialize the arguments, using `#active_job_data`. # # @param ignore_deserialization_errors [Boolean] - # Whether to ignore ActiveJob::DeserializationError when deserializing the arguments. + # Whether to ignore ActiveJob::DeserializationError and NameError when deserializing the arguments. # This is most useful if you aren't planning to use the arguments directly. def active_job(ignore_deserialization_errors: false) ActiveJob::Base.deserialize(active_job_data).tap do |aj| From a3c92c51b8b2ed7e6dcb11aabcdaed33239566ff Mon Sep 17 00:00:00 2001 From: Robert Keresnyei Date: Tue, 9 Jan 2024 22:07:27 +0100 Subject: [PATCH 5/5] Revert --- spec/rails_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 90dc68e9a..687f4332b 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -47,7 +47,7 @@ end RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_paths = [Rails.root.join("spec/fixtures")] + config.fixture_path = Rails.root.join("spec/fixtures") # RSpec Rails can automatically mix in different behaviours to your tests # based on their file location, for example enabling you to call `get` and