Skip to content

Commit

Permalink
Fix more places for kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
ofedoren authored and adamruzicka committed Jan 26, 2024
1 parent 89992e6 commit 6154281
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 24 deletions.
6 changes: 3 additions & 3 deletions lib/dynflow/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,15 @@ def save_state(conditions = {})
@step.save(conditions)
end

def delay(delay_options, *args)
Serializers::Noop.new(args)
def delay(delay_options, *args, **kwargs)
Serializers::Noop.new(args, nil, kwargs)
end

# @override to implement the action's *Plan phase* behaviour.
# By default it plans itself and expects input-hash.
# Use #plan_self and #plan_action methods to plan actions.
# It can use DB in this phase.
def plan(*args)
def plan(*args) # TODO
if from_subscription?
# if the action is triggered by subscription, by default use the
# input of parent action.
Expand Down
4 changes: 2 additions & 2 deletions lib/dynflow/action/v2/with_sub_plans.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ def check_for_errors!
end

# Helper for creating sub plans
def trigger(action_class, *args)
world.trigger { world.plan_with_options(action_class: action_class, args: args, caller_action: self) }
def trigger(action_class, *args, **kwargs)
world.trigger { world.plan_with_options(action_class: action_class, args: args, kwargs: kwargs, caller_action: self) }
end

# Concurrency limitting
Expand Down
10 changes: 5 additions & 5 deletions lib/dynflow/action/with_sub_plans.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ def abort!
end

# Helper for creating sub plans
def trigger(action_class, *args)
def trigger(action_class, *args, **kwargs)
if uses_concurrency_control
trigger_with_concurrency_control(action_class, *args)
trigger_with_concurrency_control(action_class, *args, **kwargs)
else
world.trigger { world.plan_with_options(action_class: action_class, args: args, caller_action: self) }
world.trigger { world.plan_with_options(action_class: action_class, args: args, kwargs: kwargs, caller_action: self) }
end
end

def trigger_with_concurrency_control(action_class, *args)
record = world.plan_with_options(action_class: action_class, args: args, caller_action: self)
def trigger_with_concurrency_control(action_class, *args, **kwargs)
record = world.plan_with_options(action_class: action_class, args: args, kwargs: kwargs, caller_action: self)
records = [[record.id], []]
records.reverse! unless record.state == :planned
@world.throttle_limiter.handle_plans!(execution_plan_id, *records).first
Expand Down
4 changes: 2 additions & 2 deletions lib/dynflow/execution_plan/steps/abstract_flow_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def update_from_action(action)
@queue ||= :default
end

def execute(*args)
def execute(*args, **kwargs)
return self if [:skipped, :success].include? self.state
open_action do |action|
with_meta_calculation(action) do
action.execute(*args)
action.execute(*args, **kwargs)
@delayed_events = action.delayed_events
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/dynflow/testing/assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ module Testing
module Assertions
# assert that +assert_actioned_plan+ was planned by +action+ with arguments +plan_input+
# alternatively plan-input can be asserted with +block+
def assert_action_planned_with(action, planned_action_class, *plan_input, &block)
def assert_action_planned_with(action, planned_action_class, *plan_input, **plan_input_kwargs, &block)
found_classes = assert_action_planned(action, planned_action_class)
found = found_classes.select do |a|
if plan_input.empty?
block.call a.plan_input
if plan_input.empty? && plan_input_kwargs.empty?
block.call(*a.plan_input, **a.plan_input_kwargs)
else
a.plan_input == plan_input
a.plan_input == plan_input && a.plan_input_kwargs == plan_input_kwargs
end
end

Expand Down
5 changes: 3 additions & 2 deletions lib/dynflow/testing/dummy_planned_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module Dynflow
module Testing
class DummyPlannedAction
attr_accessor :output, :plan_input
attr_accessor :output, :plan_input, :plan_input_kwargs
include Mimic

def initialize(klass)
Expand All @@ -11,8 +11,9 @@ def initialize(klass)
Testing.get_id.to_s, Testing.get_id, Testing.get_id)
end

def execute(execution_plan, event, from_subscription, *args)
def execute(execution_plan, event, from_subscription, *args, **kwargs)
@plan_input = args
@plan_input_kwargs = kwargs
self
end

Expand Down
8 changes: 4 additions & 4 deletions lib/dynflow/testing/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ def create_action_presentation(action_class)
end

# @return [Action::PlanPhase]
def plan_action(plan_action, *args, &block)
def plan_action(plan_action, *args, **kwargs, &block)
Match! plan_action.phase, Action::Plan

plan_action.execute *args, &block
plan_action.execute *args, **kwargs, &block
raise plan_action.error if plan_action.error
plan_action
end

def create_and_plan_action(action_class, *args, &block)
plan_action create_action(action_class), *args, &block
def create_and_plan_action(action_class, *args, **kwargs, &block)
plan_action create_action(action_class), *args, **kwargs, &block
end

def plan_events(world, delayed_events)
Expand Down
4 changes: 2 additions & 2 deletions lib/dynflow/world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ def delay_with_options(action_class:, args:, kwargs: {}, delay_options:, id: nil
Scheduled[execution_plan.id]
end

def plan_elsewhere(action_class, *args)
def plan_elsewhere(action_class, *args, **kwargs)
execution_plan = ExecutionPlan.new(self, nil)
execution_plan.delay(nil, action_class, {}, *args)
execution_plan.delay(nil, action_class, {}, *args, **kwargs)
plan_request(execution_plan.id)

Scheduled[execution_plan.id]
Expand Down

0 comments on commit 6154281

Please sign in to comment.