diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 857bb4d..998415a 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -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 diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7364103..96e72b3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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 @@ -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. @@ -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' @@ -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' @@ -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. @@ -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' @@ -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: diff --git a/.ruby-version b/.ruby-version index a603bb5..ff365e0 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.5 +3.1.3 diff --git a/Appraisals b/Appraisals index 8e8f0c3..f6ba35c 100644 --- a/Appraisals +++ b/Appraisals @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index f3a89e7..8213502 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,19 +8,19 @@ PATH GEM remote: https://rubygems.org/ specs: - actionmailer (7.1.2) - actionpack (= 7.1.2) - actionview (= 7.1.2) - activejob (= 7.1.2) - activesupport (= 7.1.2) + actionmailer (7.1.3.2) + actionpack (= 7.1.3.2) + actionview (= 7.1.3.2) + activejob (= 7.1.3.2) + activesupport (= 7.1.3.2) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.2) - actionpack (7.1.2) - actionview (= 7.1.2) - activesupport (= 7.1.2) + actionpack (7.1.3.2) + actionview (= 7.1.3.2) + activesupport (= 7.1.3.2) nokogiri (>= 1.8.5) racc rack (>= 2.2.4) @@ -28,22 +28,22 @@ GEM rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - actionview (7.1.2) - activesupport (= 7.1.2) + actionview (7.1.3.2) + activesupport (= 7.1.3.2) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (7.1.2) - activesupport (= 7.1.2) + activejob (7.1.3.2) + activesupport (= 7.1.3.2) globalid (>= 0.3.6) - activemodel (7.1.2) - activesupport (= 7.1.2) - activerecord (7.1.2) - activemodel (= 7.1.2) - activesupport (= 7.1.2) + activemodel (7.1.3.2) + activesupport (= 7.1.3.2) + activerecord (7.1.3.2) + activemodel (= 7.1.3.2) + activesupport (= 7.1.3.2) timeout (>= 0.4.0) - activesupport (7.1.2) + activesupport (7.1.3.2) base64 bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) @@ -59,27 +59,26 @@ GEM thor (>= 0.14.0) ast (2.4.2) base64 (0.2.0) - betterlint (1.4.9) - rubocop (> 1.0) - rubocop-performance - rubocop-rails - rubocop-rake - rubocop-rspec (>= 2.24) - bigdecimal (3.1.5) + betterlint (1.9.0) + rubocop (~> 1.62.0) + rubocop-performance (~> 1.21.0) + rubocop-rails (~> 2.24.0) + rubocop-rake (~> 0.6.0) + rubocop-rspec (~> 2.28.0) + bigdecimal (3.1.7) builder (3.2.4) - concurrent-ruby (1.2.2) + concurrent-ruby (1.2.3) connection_pool (2.4.1) crass (1.0.6) date (3.3.4) - diff-lcs (1.5.0) - drb (2.2.0) - ruby2_keywords + diff-lcs (1.5.1) + drb (2.2.1) erubi (1.12.0) globalid (1.2.1) activesupport (>= 6.1) - i18n (1.14.1) + i18n (1.14.4) concurrent-ruby (~> 1.0) - json (2.7.1) + json (2.7.2) language_server-protocol (3.17.0.3) loofah (2.22.0) crass (~> 1.0.2) @@ -90,32 +89,37 @@ GEM net-pop net-smtp mini_mime (1.1.5) - mini_portile2 (2.8.5) - minitest (5.20.0) + minitest (5.22.3) mutex_m (0.2.0) - mysql2 (0.5.5) - net-imap (0.4.9.1) + mysql2 (0.5.6) + net-imap (0.4.10) date net-protocol net-pop (0.1.2) net-protocol net-protocol (0.2.2) timeout - net-smtp (0.4.0.1) + net-smtp (0.5.0) net-protocol - nokogiri (1.15.5-arm64-darwin) + nokogiri (1.16.3-aarch64-linux) racc (~> 1.4) - nokogiri (1.15.5-x86_64-darwin) + nokogiri (1.16.3-arm-linux) racc (~> 1.4) - nokogiri (1.15.5-x86_64-linux) + nokogiri (1.16.3-arm64-darwin) + racc (~> 1.4) + nokogiri (1.16.3-x86-linux) + racc (~> 1.4) + nokogiri (1.16.3-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.16.3-x86_64-linux) racc (~> 1.4) parallel (1.24.0) - parser (3.3.0.2) + parser (3.3.0.5) ast (~> 2.4.1) racc - pg (1.5.4) + pg (1.5.6) racc (1.7.3) - rack (3.0.8) + rack (3.0.10) rack-session (2.0.0) rack (>= 3.0.0) rack-test (2.1.0) @@ -128,70 +132,77 @@ GEM loofah (~> 2.21) nokogiri (~> 1.14) rainbow (3.1.1) - rake (13.1.0) + rake (13.2.1) regexp_parser (2.9.0) rexml (3.2.6) - rspec (3.12.0) - rspec-core (~> 3.12.0) - rspec-expectations (~> 3.12.0) - rspec-mocks (~> 3.12.0) - rspec-core (3.12.2) - rspec-support (~> 3.12.0) - rspec-expectations (3.12.3) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-mocks (3.12.6) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-support (3.12.1) - rubocop (1.59.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.1) + rubocop (1.62.1) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.2.4) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.30.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.30.0) - parser (>= 3.2.1.0) + rubocop-ast (1.31.2) + parser (>= 3.3.0.4) rubocop-capybara (2.20.0) rubocop (~> 1.41) rubocop-factory_bot (2.25.1) rubocop (~> 1.41) - rubocop-performance (1.20.2) + rubocop-performance (1.21.0) rubocop (>= 1.48.1, < 2.0) - rubocop-ast (>= 1.30.0, < 2.0) - rubocop-rails (2.23.1) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rails (2.24.1) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) - rubocop-ast (>= 1.30.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) rubocop-rake (0.6.0) rubocop (~> 1.0) - rubocop-rspec (2.26.1) + rubocop-rspec (2.28.0) rubocop (~> 1.40) rubocop-capybara (~> 2.17) rubocop-factory_bot (~> 2.22) + rubocop-rspec_rails (~> 2.28) + rubocop-rspec_rails (2.28.2) + rubocop (~> 1.40) ruby-progressbar (1.13.0) - ruby2_keywords (0.0.5) - sqlite3 (1.7.0) - mini_portile2 (~> 2.8.0) - thor (1.3.0) + sqlite3 (1.7.3-aarch64-linux) + sqlite3 (1.7.3-arm-linux) + sqlite3 (1.7.3-arm64-darwin) + sqlite3 (1.7.3-x86-linux) + sqlite3 (1.7.3-x86_64-darwin) + sqlite3 (1.7.3-x86_64-linux) + thor (1.3.1) timecop (0.9.8) timeout (0.4.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.5.0) - zeitwerk (2.6.12) + zeitwerk (2.6.13) PLATFORMS - arm64-darwin-21 - arm64-darwin-22 - x86_64-darwin-21 - x86_64-darwin-22 + aarch64-linux + arm-linux + arm64-darwin + x86-linux + x86_64-darwin x86_64-linux DEPENDENCIES @@ -210,4 +221,4 @@ DEPENDENCIES zeitwerk BUNDLED WITH - 2.4.13 + 2.5.7 diff --git a/gemfiles/rails_main.gemfile b/gemfiles/rails_main.gemfile new file mode 100644 index 0000000..4fcdd25 --- /dev/null +++ b/gemfiles/rails_main.gemfile @@ -0,0 +1,22 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +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 "appraisal" +gem "betterlint" +gem "mysql2" +gem "pg" +gem "rake" +gem "rspec" +gem "sqlite3" +gem "timecop" +gem "zeitwerk" +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" + +gemspec path: "../" diff --git a/lib/delayed/active_job_adapter.rb b/lib/delayed/active_job_adapter.rb index 12d8765..ffafe6b 100644 --- a/lib/delayed/active_job_adapter.rb +++ b/lib/delayed/active_job_adapter.rb @@ -1,5 +1,11 @@ module Delayed class ActiveJobAdapter + class UnsafeEnqueueError < RuntimeError; end + + def enqueue_after_transaction_commit? + false + end + def enqueue(job) _enqueue(job) end @@ -11,6 +17,10 @@ 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 + raise UnsafeEnqueueError, "The ':delayed' ActiveJob adapter is not compatible with enqueue_after_transaction_commit" + end + opts.merge!({ queue: job.queue_name, priority: job.priority }.compact) .merge!(job.provider_attributes || {}) diff --git a/spec/delayed/active_job_adapter_spec.rb b/spec/delayed/active_job_adapter_spec.rb index 53afa01..402ee20 100644 --- a/spec/delayed/active_job_adapter_spec.rb +++ b/spec/delayed/active_job_adapter_spec.rb @@ -287,6 +287,19 @@ def perform(arg, kwarg:) end end + if ActiveJob.gem_version.release >= Gem::Version.new('7.2') + 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 + end + context 'when using the ActiveJob test adapter' do let(:queue_adapter) { :test }