Skip to content

Commit

Permalink
Prepare for Rails 7.2 support (and disable enqueue_after_transaction_…
Browse files Browse the repository at this point in the history
…commit) (#40)

This anticipates the release of a new feature in Rails 7.2 introduced here: rails/rails#51426

In Rails 7.2, ActiveJob will default `enqueue_after_transaction_commit` to `true`, and we would like to explicitly set this to `false` (retaining transactional enqueues, since `delayed` is DB-backed).

This PR goes a step further and also raises a `UnsafeEnqueueError` if, during enqueue, it encounters any job type that has overridden `enqueue_after_transaction_commit` to `true`. Worth noting that this exception may still be raised _after transaction commit_ (based on the way the lifecycle hooks are handled), so it is intended first and foremost as a guard during development & testing.

As part of this change I also:
- Added a new Appraisal for the latest Rails main build on GitHub.
- Re-generated the rubocop todo file. There are changes we can pull out & autocorrect, but we can do them in separate PRs.
  • Loading branch information
smudge authored Apr 29, 2024
1 parent 77b97e9 commit 9a328c6
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 89 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up Ruby 2.7
- name: Set up Ruby 3.2
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
ruby-version: '3.2'
bundler-cache: true
- name: Run Linter
run: bundle exec rubocop --parallel
95 changes: 83 additions & 12 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 99999`
# on 2023-01-20 19:16:15 UTC using RuboCop version 1.43.0.
# on 2024-04-05 18:41:42 UTC using RuboCop version 1.62.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -17,6 +17,14 @@ Betterment/ActiveJobPerformable:
- 'spec/autoloaded/struct.rb'
- 'spec/sample_jobs.rb'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
Bundler/OrderedGems:
Exclude:
- 'gemfiles/rails_main.gemfile'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Severity, Include.
Expand All @@ -32,7 +40,14 @@ Lint/ConstantDefinitionInBlock:
Exclude:
- 'spec/message_sending_spec.rb'

# Offense count: 1
# Configuration parameters: DebuggerMethods.
Lint/Debugger:
Exclude:
- 'spec/helper.rb'

# Offense count: 2
# Configuration parameters: AllowedParentClasses.
Lint/MissingSuper:
Exclude:
- 'lib/delayed/message_sending.rb'
Expand All @@ -50,7 +65,7 @@ Lint/SuppressedException:
- 'lib/delayed/backend/base.rb'

# Offense count: 4
# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, CountRepeatedAttributes, Max.
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
Metrics/AbcSize:
Exclude:
- 'lib/delayed/message_sending.rb'
Expand All @@ -62,14 +77,6 @@ RSpec/AnyInstance:
Exclude:
- 'spec/delayed/job_spec.rb'

# Offense count: 18
# This cop supports unsafe autocorrection (--autocorrect-all).
RSpec/BeEq:
Exclude:
- 'spec/delayed/job_spec.rb'
- 'spec/delayed/priority_spec.rb'
- 'spec/message_sending_spec.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
Expand Down Expand Up @@ -165,11 +172,10 @@ Rake/DuplicateTask:
Exclude:
- 'Rakefile'

# Offense count: 4
# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
Security/YAMLLoad:
Exclude:
- 'spec/delayed/serialization/active_record_spec.rb'
- 'spec/helper.rb'
- 'spec/yaml_ext_spec.rb'

Expand All @@ -180,6 +186,71 @@ Style/FetchEnvVar:
Exclude:
- 'spec/helper.rb'

# Offense count: 58
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Exclude:
- 'Appraisals'
- 'Rakefile'
- 'app/models/delayed/job.rb'
- 'delayed.gemspec'
- 'gemfiles/rails_5_2.gemfile'
- 'gemfiles/rails_6_0.gemfile'
- 'gemfiles/rails_6_1.gemfile'
- 'gemfiles/rails_7_0.gemfile'
- 'gemfiles/rails_7_1.gemfile'
- 'gemfiles/rails_main.gemfile'
- 'lib/delayed.rb'
- 'lib/delayed/active_job_adapter.rb'
- 'lib/delayed/backend/base.rb'
- 'lib/delayed/backend/job_preparer.rb'
- 'lib/delayed/engine.rb'
- 'lib/delayed/exceptions.rb'
- 'lib/delayed/job_wrapper.rb'
- 'lib/delayed/lifecycle.rb'
- 'lib/delayed/message_sending.rb'
- 'lib/delayed/monitor.rb'
- 'lib/delayed/performable_mailer.rb'
- 'lib/delayed/performable_method.rb'
- 'lib/delayed/plugin.rb'
- 'lib/delayed/plugins/connection.rb'
- 'lib/delayed/plugins/instrumentation.rb'
- 'lib/delayed/priority.rb'
- 'lib/delayed/psych_ext.rb'
- 'lib/delayed/runnable.rb'
- 'lib/delayed/serialization/active_record.rb'
- 'lib/delayed/syck_ext.rb'
- 'lib/delayed/tasks.rb'
- 'lib/delayed/worker.rb'
- 'lib/delayed/yaml_ext.rb'
- 'lib/delayed_job.rb'
- 'lib/delayed_job_active_record.rb'
- 'lib/generators/delayed/generator.rb'
- 'lib/generators/delayed/migration_generator.rb'
- 'lib/generators/delayed/next_migration_version.rb'
- 'spec/autoloaded/clazz.rb'
- 'spec/autoloaded/instance_clazz.rb'
- 'spec/autoloaded/instance_struct.rb'
- 'spec/autoloaded/struct.rb'
- 'spec/delayed/active_job_adapter_spec.rb'
- 'spec/delayed/job_spec.rb'
- 'spec/delayed/monitor_spec.rb'
- 'spec/delayed/plugins/instrumentation_spec.rb'
- 'spec/delayed/priority_spec.rb'
- 'spec/delayed/serialization/active_record_spec.rb'
- 'spec/delayed/tasks_spec.rb'
- 'spec/helper.rb'
- 'spec/lifecycle_spec.rb'
- 'spec/message_sending_spec.rb'
- 'spec/performable_mailer_spec.rb'
- 'spec/performable_method_spec.rb'
- 'spec/psych_ext_spec.rb'
- 'spec/sample_jobs.rb'
- 'spec/worker_spec.rb'
- 'spec/yaml_ext_spec.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/MinMaxComparison:
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.5
3.1.3
10 changes: 10 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ appraise 'rails-7-1' do
gem 'activejob', '~> 7.1.0'
gem 'activerecord', '~> 7.1.0'
end

appraise 'rails-main' do
gem 'actionmailer', github: 'rails/rails', glob: 'actionmailer/*.gemspec'
gem 'activejob', github: 'rails/rails', glob: 'activejob/*.gemspec'
gem 'activerecord', github: 'rails/rails', glob: 'activerecord/*.gemspec'
gem 'actionview', github: 'rails/rails', glob: 'actionview/*.gemspec'
gem 'actionpack', github: 'rails/rails', glob: 'actionpack/*.gemspec'
gem 'activesupport', github: 'rails/rails', glob: 'activesupport/*.gemspec'
gem 'activemodel', github: 'rails/rails', glob: 'activemodel/*.gemspec'
end
Loading

0 comments on commit 9a328c6

Please sign in to comment.