Skip to content

Commit

Permalink
Fixes #37103 - Update kwargs usage to comply with Ruby 3
Browse files Browse the repository at this point in the history
  • Loading branch information
ofedoren committed Jan 25, 2024
1 parent 5c2d1fb commit bef7184
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions app/models/foreman_tasks/concerns/action_triggering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def update_action; end
# @override
def destroy_action; end

def save(*args)
dynflow_task_wrap(:save) { super(*args) }
def save(...)
dynflow_task_wrap(:save) { super(...) }
end

def save!(*args)
dynflow_task_wrap(:save) { super(*args) }
def save!(...)
dynflow_task_wrap(:save) { super(...) }
end

def destroy
Expand All @@ -37,14 +37,14 @@ def destroy

# In order to use host.<attribute>_changed?, we must assign_attributes to
# the host record for these update and update! methods.
def update(*args)
assign_attributes(*args)
def update(...)
assign_attributes(...)
dynflow_task_wrap(:save) { save }
end
alias update_attributes update

def update!(*args)
assign_attributes(*args)
def update!(...)
assign_attributes(...)
dynflow_task_wrap(:save) { save! }
end
alias update_attributes! update!
Expand Down Expand Up @@ -88,9 +88,9 @@ def plan_hook_action
# We do it separately from the execution phase, because the transaction
# of planning phase is expected to be commited when execution occurs. Also
# we want to be able to rollback the whole db operation when planning fails.
def plan_action(action_class, *args)
def plan_action(action_class, *args, **kwargs)
return if ForemanTasks.dynflow.config.disable_active_record_actions
@execution_plan = ::ForemanTasks.dynflow.world.plan(action_class, *args)
@execution_plan = ::ForemanTasks.dynflow.world.plan(action_class, *args, **kwargs)
raise @execution_plan.errors.first if @execution_plan.error?
end

Expand Down
20 changes: 10 additions & 10 deletions lib/foreman_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ def self.dynflow
@dynflow ||= ForemanTasks::Dynflow.new(nil, ForemanTasks::Dynflow::Configuration.new)
end

def self.trigger(action, *args, &block)
dynflow.world.trigger action, *args, &block
def self.trigger(action, *args, **kwargs, &block)
dynflow.world.trigger action, *args, **kwargs, &block
end

def self.trigger_task(async, action, *args, &block)
def self.trigger_task(async, action, *args, **kwargs, &block)
rails_safe_trigger_task do
Match! async, true, false
match trigger(action, *args, &block),
match trigger(action, *args, **kwargs, &block),
(on ::Dynflow::World::PlaningFailed.call(error: ~any) do |error|
raise error
end),
Expand All @@ -47,18 +47,18 @@ def self.rails_safe_trigger_task
end
end

def self.async_task(action, *args, &block)
trigger_task true, action, *args, &block
def self.async_task(action, *args, **kwargs, &block)
trigger_task true, action, *args, **kwargs, &block
end

def self.sync_task(action, *args, &block)
trigger_task(false, action, *args, &block).tap do |task|
def self.sync_task(action, *args, **kwargs, &block)
trigger_task(false, action, *args, **kwargs, &block).tap do |task|
raise TaskError, task if task.execution_plan.error? || task.execution_plan.result == :warning
end
end

def self.delay(action, delay_options, *args)
result = dynflow.world.delay action, delay_options, *args
def self.delay(action, delay_options, *args, **kwargs)
result = dynflow.world.delay action, delay_options, *args, **kwargs
ForemanTasks::Task::DynflowTask.where(:external_id => result.id).first!
end

Expand Down

0 comments on commit bef7184

Please sign in to comment.