diff --git a/lib/lev/active_job/base.rb b/lib/lev/active_job/base.rb index e380856..469994d 100644 --- a/lib/lev/active_job/base.rb +++ b/lib/lev/active_job/base.rb @@ -3,7 +3,7 @@ module ActiveJob class Base < Lev.configuration.job_class attr_accessor(:provider_job_id) unless respond_to?(:provider_job_id) - def perform_later(routine_class, options, *args, &block) + def perform_later(routine_class, options, *args, **kwargs, &block) # Create a new status object status = routine_class.create_status @@ -25,7 +25,7 @@ def perform_later(routine_class, options, *args, &block) # Queue up the job and set the provider_job_id # For delayed_job, requires either Rails 5 or # http://stackoverflow.com/questions/29855768/rails-4-2-get-delayed-job-id-from-active-job - provider_job_id = self.class.send(:job_or_instantiate, *args, &block) + provider_job_id = self.class.send(:job_or_instantiate, *args, **kwargs, &block) .enqueue(options) .provider_job_id status.set_provider_job_id(provider_job_id) \ @@ -35,14 +35,14 @@ def perform_later(routine_class, options, *args, &block) status.id end - def perform(*args, &block) + def perform(*args, **kwargs, &block) # Pop arguments added by perform_later id = args.pop routine_class = Kernel.const_get(args.pop) routine_instance = routine_class.new(routine_class.find_status(id)) - routine_instance.call(*args, &block) + routine_instance.call(*args, **kwargs, &block) end end end diff --git a/lib/lev/active_job/configured_job.rb b/lib/lev/active_job/configured_job.rb index 71cf1f7..5ff6c97 100644 --- a/lib/lev/active_job/configured_job.rb +++ b/lib/lev/active_job/configured_job.rb @@ -12,8 +12,8 @@ def options routine_class.active_job_enqueue_options.merge(@options) end - def perform_later(*args, &block) - routine_class.job_class.new.perform_later(routine_class, options, *args, &block) + def perform_later(*args, **kwargs, &block) + routine_class.job_class.new.perform_later(routine_class, options, *args, **kwargs, &block) end end end diff --git a/lib/lev/null_status.rb b/lib/lev/null_status.rb index 7b59229..e2d8053 100644 --- a/lib/lev/null_status.rb +++ b/lib/lev/null_status.rb @@ -14,7 +14,7 @@ def kill_requested? @kill_requested end - def method_missing(*args, &block) + def method_missing(*args, **kwargs, &block) nil end diff --git a/lib/lev/routine.rb b/lib/lev/routine.rb index 4e19241..ffe1f6b 100644 --- a/lib/lev/routine.rb +++ b/lib/lev/routine.rb @@ -200,12 +200,12 @@ def self.included(base) end module ClassMethods - def call(*args, &block) - new.call(*args, &block) + def call(*args, **kwargs, &block) + new.call(*args, **kwargs, &block) end - def [](*args, &block) - result = call(*args, &block) + def [](*args, **kwargs, &block) + result = call(*args, **kwargs, &block) result.errors.raise_exception_if_any! result.outputs.send(@express_output) end @@ -222,9 +222,9 @@ def active_job_enqueue_options @active_job_enqueue_options || { queue: :default } end - def perform_later(*args, &block) + def perform_later(*args, **kwargs, &block) # Delegate to a subclass of Lev::Routine::ActiveJob::Base - job_class.new.perform_later(self, active_job_enqueue_options, *args, &block) + job_class.new.perform_later(self, active_job_enqueue_options, *args, **kwargs, &block) end # Called at a routine's class level to foretell which other routines will @@ -279,7 +279,7 @@ def find_status(id) attr_reader :runner - def call(*args, &block) + def call(*args, **kwargs, &block) @after_transaction_blocks = [] status.started! @@ -290,9 +290,9 @@ def call(*args, &block) catch :fatal_errors_encountered do if self.class.delegates_to - run(self.class.delegates_to, *args, &block) + run(self.class.delegates_to, *args, **kwargs, &block) else - exec(*args, &block) + exec(*args, **kwargs, &block) end end end @@ -324,7 +324,7 @@ def transaction_run_by?(who) who == topmost_runner && who.class.transaction_isolation != TransactionIsolation.no_transaction end - def run(other_routine, *args, &block) + def run(other_routine, *args, **kwargs, &block) options = {} if other_routine.is_a? Array @@ -395,7 +395,7 @@ def run(other_routine, *args, &block) # other_routine.runner = self - run_result = other_routine.call(*args, &block) + run_result = other_routine.call(*args, **kwargs, &block) run_result.outputs.transfer_to(outputs) do |name| output_mapper.map(name) @@ -495,7 +495,15 @@ def runner=(runner) def in_transaction(options={}) if transaction_run_by?(self) isolation_symbol = self.class.transaction_isolation.symbol - if ActiveRecord::VERSION::MAJOR >= 4 + if (ActiveRecord::VERSION::MAJOR >= 8 || + (ActiveRecord::VERSION::MAJOR == 7 && ActiveRecord::VERSION::MINOR >= 1)) && + ActiveRecord::Base.connection.transaction_open? + # Don't even try to set transaction isolation if the transaction is already open + ActiveRecord::Base.transaction do + yield + raise ActiveRecord::Rollback if errors? + end + elsif ActiveRecord::VERSION::MAJOR >= 4 begin ActiveRecord::Base.transaction(isolation: isolation_symbol) do yield diff --git a/lib/lev/version.rb b/lib/lev/version.rb index b42e2c1..cb815c6 100644 --- a/lib/lev/version.rb +++ b/lib/lev/version.rb @@ -1,3 +1,3 @@ module Lev - VERSION = '12.0.0' + VERSION = '12.1.0' end