From d5a9d852ba081e0b8821fa5673ca3fa76db0b35b Mon Sep 17 00:00:00 2001 From: Ben Sheldon Date: Wed, 18 Aug 2021 11:49:16 -0700 Subject: [PATCH] Add deprecation notice that `async` mode will be renamed `async_all` in GoodJob v2.0 --- lib/good_job/adapter.rb | 2 +- lib/good_job/configuration.rb | 15 +++++++++++++-- spec/lib/good_job/adapter_spec.rb | 10 +++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/good_job/adapter.rb b/lib/good_job/adapter.rb index 241688e9d..48e3ac9dd 100644 --- a/lib/good_job/adapter.rb +++ b/lib/good_job/adapter.rb @@ -130,7 +130,7 @@ def shutdown(timeout: :default, wait: nil) # Whether in +:async+ execution mode. # @return [Boolean] def execute_async? - @configuration.execution_mode == :async || + @configuration.execution_mode.in?([:async, :async_all]) || @configuration.execution_mode == :async_server && in_server_process? end diff --git a/lib/good_job/configuration.rb b/lib/good_job/configuration.rb index 74d63dd16..5e48a0e02 100644 --- a/lib/good_job/configuration.rb +++ b/lib/good_job/configuration.rb @@ -7,7 +7,7 @@ module GoodJob # class Configuration # Valid execution modes. - EXECUTION_MODES = [:async, :async_server, :external, :inline].freeze + EXECUTION_MODES = [:async, :async_all, :async_server, :external, :inline].freeze # Default number of threads to use per {Scheduler} DEFAULT_MAX_THREADS = 5 # Default number of seconds between polls for jobs @@ -58,7 +58,18 @@ def execution_mode end if mode - mode.to_sym + mode_sym = mode.to_sym + if mode_sym == :async + ActiveSupport::Deprecation.warn <<~DEPRECATION + The next major version of GoodJob will redefine the meaning of 'async' + execution mode to be equivalent to 'async_server' and only execute + within the webserver process. + + To continue using the v1.0 semantics of 'async', use `async_all` instead. + + DEPRECATION + end + mode_sym elsif Rails.env.development? || Rails.env.test? :inline else diff --git a/spec/lib/good_job/adapter_spec.rb b/spec/lib/good_job/adapter_spec.rb index 612ea0fcb..abfb30e20 100644 --- a/spec/lib/good_job/adapter_spec.rb +++ b/spec/lib/good_job/adapter_spec.rb @@ -80,7 +80,7 @@ end describe '#execute_async?' do - context 'when execution mode async_all' do + context 'when execution mode async' do let(:adapter) { described_class.new(execution_mode: :async) } it 'returns true' do @@ -88,6 +88,14 @@ end end + context 'when execution mode async_all' do + let(:adapter) { described_class.new(execution_mode: :async_all) } + + it 'returns true' do + expect(adapter.execute_async?).to eq true + end + end + context 'when execution mode async_server' do let(:adapter) { described_class.new(execution_mode: :async_server) }