Skip to content

Commit

Permalink
Merge pull request #73 from lml/ruby-3
Browse files Browse the repository at this point in the history
Support ruby 3
  • Loading branch information
Dantemss authored Mar 11, 2024
2 parents a6aec28 + c0dc6cc commit 573a1ce
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
8 changes: 4 additions & 4 deletions lib/lev/active_job/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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) \
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/lev/active_job/configured_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/lev/null_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def kill_requested?
@kill_requested
end

def method_missing(*args, &block)
def method_missing(*args, **kwargs, &block)
nil
end

Expand Down
32 changes: 20 additions & 12 deletions lib/lev/routine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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!
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/lev/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Lev
VERSION = '12.0.0'
VERSION = '12.1.0'
end

0 comments on commit 573a1ce

Please sign in to comment.