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 Rails 8.0 deprecation #51

Merged
merged 4 commits into from
Jan 24, 2025
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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
delayed (0.7.0)
delayed (0.7.1)
activerecord (>= 5.2)
concurrent-ruby

Expand Down
2 changes: 1 addition & 1 deletion delayed.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']
spec.summary = 'a multi-threaded, SQL-driven ActiveJob backend used at Betterment to process millions of background jobs per day'

spec.version = '0.7.0'
spec.version = '0.7.1'
spec.metadata = {
'changelog_uri' => 'https://github.com/betterment/delayed/blob/main/CHANGELOG.md',
'bug_tracker_uri' => 'https://github.com/betterment/delayed/issues',
Expand Down
7 changes: 6 additions & 1 deletion lib/delayed/active_job_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def enqueue_at(job, timestamp)
private

def _enqueue(job, opts = {})
if job.class.respond_to?(:enqueue_after_transaction_commit) && job.class.enqueue_after_transaction_commit == :always
if enqueue_after_transaction_commit_enabled?(job)
raise UnsafeEnqueueError, "The ':delayed' ActiveJob adapter is not compatible with enqueue_after_transaction_commit"
end

Expand All @@ -29,6 +29,11 @@ def _enqueue(job, opts = {})
end
end

def enqueue_after_transaction_commit_enabled?(job)
job.class.respond_to?(:enqueue_after_transaction_commit) &&
[true, :always].include?(job.class.enqueue_after_transaction_commit)
end

module EnqueuingPatch
def self.included(klass)
klass.prepend PrependedMethods
Expand Down
32 changes: 30 additions & 2 deletions spec/delayed/active_job_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ def perform(arg, kwarg:)
end

it 'raises an exception on enqueue' do
expect { JobClass.perform_later }.to raise_error(Delayed::ActiveJobAdapter::UnsafeEnqueueError)
ActiveJob.deprecator.silence do
expect { JobClass.perform_later }.to raise_error(Delayed::ActiveJobAdapter::UnsafeEnqueueError)
end
end
end

Expand All @@ -306,7 +308,33 @@ def perform(arg, kwarg:)
end

it 'does not raises an exception on enqueue' do
expect { JobClass.perform_later }.not_to raise_error(Delayed::ActiveJobAdapter::UnsafeEnqueueError)
ActiveJob.deprecator.silence do
expect { JobClass.perform_later }.not_to raise_error
end
end
end
end

if ActiveJob.gem_version.release >= Gem::Version.new('8.0')
context 'when the given job sets enqueue_after_transaction_commit to true' do
before do
JobClass.include ActiveJob::EnqueueAfterTransactionCommit # normally run in an ActiveJob railtie
JobClass.enqueue_after_transaction_commit = true
end

it 'raises an exception on enqueue' do
expect { JobClass.perform_later }.to raise_error(Delayed::ActiveJobAdapter::UnsafeEnqueueError)
end
end

context 'when the given job sets enqueue_after_transaction_commit to false' do
before do
JobClass.include ActiveJob::EnqueueAfterTransactionCommit # normally run in an ActiveJob railtie
JobClass.enqueue_after_transaction_commit = false
end

it 'does not raises an exception on enqueue' do
expect { JobClass.perform_later }.not_to raise_error
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@

require 'rake'

if ActiveSupport.gem_version >= Gem::Version.new('7.1')
frameworks = [ActiveModel, ActiveRecord, ActionMailer, ActiveJob, ActiveSupport]
frameworks.each { |framework| framework.deprecator.behavior = :raise }
else
ActiveSupport::Deprecation.behavior = :raise
end

if ENV['DEBUG_LOGS']
Delayed.logger = Logger.new($stdout)
else
Expand Down
Loading