Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix discard job with nonexistent job class #1211

Merged
merged 6 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/models/good_job/base_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ 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|
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
Expand Down
12 changes: 12 additions & 0 deletions spec/app/models/good_job/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down